Part Number Hot Search : 
30009 D5000 00C562 6143A 933070 PWR1110 RPM873 01726203
Product Description
Full Text Search
 

To Download PIC18F25K80ESOIC Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ? 2011 microchip technology inc. ds39977d pic18f66k80 family data sheet 28/40/44/64-pin, enhanced flash microcontrollers, with ecan? and nanowatt xlp technology
ds39977d-page 2 ? 2011 microchip technology inc. information contained in this publication regarding device applications and the like is provided only for your convenience and may be superseded by updates. it is your responsibility to ensure that your application meets with your specifications. microchip makes no representations or warranties of any kind whether express or implied, written or oral, statutory or otherwise, related to the information, including but not limited to its condition, quality, performance, merchantability or fitness for purpose . microchip disclaims all liability arising from this information and its use. use of microchip devices in life support and/or safety applications is entirely at the buyer?s risk, and the buyer agrees to defend, indemnify and hold harmless microchip from any and all damages, claims, suits, or expenses resulting from such use. no licenses are conveyed, implicitly or otherwise, under any microchip intellectual property rights. trademarks the microchip name and logo, the microchip logo, dspic, k ee l oq , k ee l oq logo, mplab, pic, picmicro, picstart, pic 32 logo, rfpic and uni/o are registered trademarks of microchip technology incorporated in the u.s.a. and other countries. filterlab, hampshire, hi-tech c, linear active thermistor, mxdev, mxlab, seeval and the embedded control solutions company are registered trademarks of microchip technology incorporated in the u.s.a. analog-for-the-digital age, appl ication maestro, codeguard, dspicdem, dspicdem.net, dspicworks, dsspeak, ecan, economonitor, fansense, hi-tide, in-circuit serial programming, icsp, mindi, miwi, mpasm, mplab certified logo, mplib, mplink, mtouch, omniscient code generation, picc, picc-18, picdem, picdem.net, pickit, pictail, real ice, rflab, select mode, total endurance, tsharc, uniwindriver, wiperlock and zena are trademarks of microchip tec hnology incorporated in the u.s.a. and other countries. sqtp is a service mark of microchip technology incorporated in the u.s.a. all other trademarks mentioned herein are property of their respective companies. ? 2011, microchip technology incorporated, printed in the u.s.a., all rights reserved. printed on recycled paper. isbn: 978-1-61341-808-6 note the following details of the code protection feature on microchip devices: ? microchip products meet the specification cont ained in their particular microchip data sheet. ? microchip believes that its family of products is one of the mo st secure families of its kind on the market today, when used i n the intended manner and under normal conditions. ? there are dishonest and possibly illegal methods used to breach the code protection feature. all of these methods, to our knowledge, require using the microchip produc ts in a manner outside the operating specifications contained in microchip?s data sheets. most likely, the person doing so is engaged in theft of intellectual property. ? microchip is willing to work with the customer who is concerned about the integrity of their code. ? neither microchip nor any other semiconductor manufacturer c an guarantee the security of their code. code protection does not mean that we are guaranteeing the product as ?unbreakable.? code protection is constantly evolving. we at microchip are co mmitted to continuously improvi ng the code protection features of our products. attempts to break microchip?s c ode protection feature may be a violation of the digital millennium copyright act. if such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that act. microchip received iso/ts-16949:2002 certification for its worldwide headquarters, design and wafer fabrication facilities in chandler and tempe, arizona; gresham, oregon and design centers in california and india. the company?s quality system processes and procedures are for its pic ? mcus and dspic ? dscs, k ee l oq ? code hopping devices, serial eeproms, microperipherals, nonvolatile memory and analog products. in addition, microchip?s quality system for the design and manufacture of development systems is iso 9001:2000 certified.
? 2011 microchip technology inc. ds39977d-page 3 power-managed modes: ? run: cpu on, peripherals on ? idle: cpu off, peripherals on ? sleep: cpu off, peripherals off ? two-speed oscillator start-up ? fail-safe clock monitor (fscm) ? power-saving peripheral module disable (pmd) ? ultra low-power wake-up ? fast wake-up, 1 ? s, typical ? low-power wdt, 300 na, typical ? run mode currents down to very low 3.8 ? a, typical ? idle mode currents down to very low 880 na, typical ? sleep mode current down to very low 13 na, typical ecan bus module features: ? conforms to can 2.0b active specification ? three operating modes: - legacy mode (full backward compatibility with existing pic18cxx8/fxx8 can modules) - enhanced mode - fifo mode or programmable tx/rx buffers ? message bit rates up to 1 mbps ? devicenet? data byte filter support ? six programmable receive/transmit buffers ? three dedicated transmit buffers with prioritization ? two dedicated receive buffers ecan bus module features (continued): ? 16 full, 29-bit acceptance filters with dynamic association ? three full, 29-bit acceptance masks ? automatic remote frame handling ? advanced error management features special microcontroller features: ? operating voltage range: 1.8v to 5.5v ? on-chip 3.3v regulator ? operating speed up to 64 mhz ? up to 64 kbytes on-chip flash program memory: - 10,000 erase/write cycle, typical - 20 years minimum retention, typical ? 1,024 bytes of data eeprom: - 100,000 erase/write cycle data eeprom memory, typical ? 3.6 kbytes of general purpose registers (sram) ? three internal oscillators: lf-intosc (31 khz), mf-intosc (500 khz) and hf-intosc (16 mhz) ? self-programmable under software control ? priority levels for interrupts ? 8 x 8 single-cycle hardware multiplier ? extended watchdog timer (wdt): - programmable period from 4 ms to 4,194s ? in-circuit serial programming? (icsp?) via two pins ? in-circuit debug via two pins ? programmable bor ? programmable lvd table 1: device comparison device program memory data memory (bytes) data ee (bytes) pins i/o ctmu 12-bit a/d channels ccp/ eccp timers 8-bit/16-bit eusart comparators ecan? mssp bormv/lvd dsm pic18f25k80 32 kbytes 3,648 1,024 28 24 1 8-ch 4/1 2/3 2 2 1 1 yes no pic18lf25k80 32 kbytes 3,648 1,024 28 24 1 8-ch 4/1 2/3 2 2 1 1 yes no pic18f26k80 64 kbytes 3,648 1,024 28 24 1 8-ch 4/1 2/3 2 2 1 1 yes no pic18lf26k80 64 kbytes 3,648 1,024 28 24 1 8-ch 4/1 2/3 2 2 1 1 yes no pic18f45k80 32 kbytes 3,648 1,024 40/44 35 1 11-ch 4/1 2/3 2 2 1 1 yes no pic18lf45k80 32 kbytes 3,648 1,024 40/44 35 1 11-ch 4/1 2/3 2 2 1 1 yes no pic18f46k80 64 kbytes 3,648 1,024 40/44 35 1 11-ch 4/1 2/3 2 2 1 1 yes no pic18lf46k80 64 kbytes 3,648 1,024 40/44 35 1 11-ch 4/1 2/3 2 2 1 1 yes no pic18f65k80 32 kbytes 3,648 1,024 64 54 1 11-ch 4/1 2/3 2 2 1 1 yes yes pic18lf65k80 32 kbytes 3,648 1,024 64 54 1 11-ch 4/1 2/3 2 2 1 1 yes yes pic18f66k80 64 kbytes 3,648 1,024 64 54 1 11-ch 4/1 2/3 2 2 1 1 yes yes pic18lf66k80 64 kbytes 3,648 1,024 64 54 1 11-ch 4/1 2/3 2 2 1 1 yes yes pic18f66k80 family 28/40/44/64-pin, enhanced flash microcontrollers with ecan? and nanowatt xlp technology
pic18f66k80 family ds39977d-page 4 ? 2011 microchip technology inc. peripheral highlights: ? five ccp/eccp modules: - four capture/compare/pwm (ccp) modules - one enhanced capture/compare/pwm (eccp) module ? five 8/16-bit timer/counter modules: - timer0: 8/16-bit timer/counter with 8-bit programmable prescaler - timer1, 3: 16-bit timer/counter - timer2, 4: 8-bit timer/counter ? two analog comparators ? configurable reference clock output ? charge time measurement unit (ctmu): - capacitance measurement - time measurement with 1 ns typical resolution - integrated voltage reference ? high-current sink/source 25 ma/25 ma (portb and portc) ? up to four external interrupts ? one master synchronous serial port (mssp) module: - 3/4-wire spi (supports all four spi modes) -i 2 c? master and slave modes ? two enhanced addressable usart modules: - lin/j2602 support - auto-baud detect (abd) ? 12-bit a/d converter with up to 11 channels: - auto-acquisition and sleep operation - differential input mode of operation ? data signal modulator module: - select modulator and carrier sources from vari- ous module outputs ? integrated voltage reference
? 2011 microchip technology inc. ds39977d-page 5 pic18f66k80 family pin diagrams ra1/an1 rb3/canrx/c2out/p1d/cted2/int3 ra2/v ref -/an2 v ddcore /v cap ra5/an4/c2inb/hlvdin/t1cki/ss /ctmui osc1/clkin/ra7 28-pin qfn (1) 1 2 3 4 7 5 6 21 20 19 18 15 17 16 28 27 26 25 24 23 22 8 9 10 11 12 13 14 ra0/cv ref /an0/ulpwu mclr /re3 rb7/pgd/t3g/rx2/dt2/kbi3 rc0/sosco/sclki rc1/sosci rc2/t1g/ccp2 rc3/refo/scl/sck pic18f2xk80 pic18lf2xk80 ra3/v ref +/an3 v ss osc2/clkout/ra6 rb2/cantx/c1out/p1c/cted1/int2 rb1/an8/c1inb/p1b/ctdin/int1 rb0/an10/c1ina/flt0/int0 v dd v ss rc7/canrx/rx1/dt1/ccp4 rc4/sda/sdi rc5/sdo rc6/cantx/tx1/ck1/ccp3 rb6/pgc/tx2/ck2/kbi2 rb5/t0cki/t3cki/ccp5/kbi1 rb4/an9/c2ina/eccp1/p1a/ctpls/kbi0 note 1: for the qfn package, it is recommended that the bottom pad be connected to v ss .
pic18f66k80 family ds39977d-page 6 ? 2011 microchip technology inc. pin diagrams (continued) ra1/an1 rb3/canrx/c2out/p1d/cted2/int3 ra2/v ref -/an2 v ddcore /v cap ra5/an4/c2inb/hlvdin/t1cki/ss /ctmui osc1/clkin/ra7 28-pin ssop/spdip/soic rb7/pgd/t3g/rx2/dt2/kbi3 1 2 3 4 7 5 6 8 9 10 11 14 12 13 19 18 15 17 16 24 23 20 22 21 25 26 27 28 pic18f2xk80 pic18lf2xk80 ra3/v ref +/an3 v ss osc2/clkout/ra6 rb2/cantx/c1out/p1c/cted1/int2 rb1/an8/c1inb/p1b/ctdin/int1 rb0/an10/c1ina/flt0/int0 v dd v ss rc7/canrx/rx1/dt1/ccp4 rc4/sda/sdi rc5/sdo rc6/cantx/tx1/ck1/ccp3 rb6/pgc/tx2/ck2/kbi2 rb5/t0cki/t3cki/ccp5/kbi1 rb4/an9/c2ina/eccp1/p1a/ctpls/kbi0 1 2 3 4 7 5 6 8 9 10 11 14 12 13 19 18 15 17 16 24 23 20 22 21 25 26 27 28 pic18f4xk80 pic18lf4xk80 40-pin pdip mclr /re3 ra0/cv ref /an0/ulpwu rc0/sosco/sclki rc1/isosci rc2/t1g/ccp2 rc3/refo/scl/sck 32 31 30 29 33 34 35 36 37 38 39 40 mclr /re3 ra0/cv ref /an0/ulpwu ra1/an1/c1inc ra2/v ref -/an2/c2inc ra3/v ref +/an3 v ddcore /v cap ra5/an4/hlvdin/t1cki/ss re0/an5/rd re1/an6/c1out/wr re2/an7/c2out/cs v dd v ss osc1/clkin/ra7 osc2/clkout/ra6 rc0/sosco/sclki rc1/sosci rc2/t1g/ccp2 rc3/refo/scl/sck rd0/c1ina/psp0 rd1/c1inb/psp1 rb3/canrx/cted2/int3 rb7/pgd/t3g/kbi3 rb2/cantx/cted1/int2 rb1/an8/ctdin/int1 rb0/an10/flt0/int0 v dd v ss rb6/pgc/kbi2 rb5/t0cki/t3cki/ccp5/kbi1 rb4/an9/ctpls/kbi0 rd7/rx2/dt2/p1d/psp7 rd6/tx2/ck2/p1c/psp6 rd5/p1b/psp5 rd4/eccp1/p1a/psp4 rc7/canrx/rx1/dt1/ccp4 rc6/cantx/tx1/ck1/ccp3 rc5/sdo rc4/sda/sdi rd3/c2inb/ctmui/psp3 rd2/c2ina/psp2
? 2011 microchip technology inc. ds39977d-page 7 pic18f66k80 family pin diagrams (continued) 44-pin tqfp ra1/an1/c1inc rb3/canrx/cted2/int3 ra2/v ref -/an2/c2inc v ddcore /v cap ra5/an4/hlvdin/t1cki/ss 1 2 3 4 7 5 6 33 32 19 18 15 17 28 27 26 25 24 23 22 8 9 10 11 12 13 14 ra0/cv ref /an0/ulpwu mclr /re3 rb7/pgd/t3g/kbi3 rc0/sosco/sclki rc1/sosci rc2/t1g/ccp2 rc3/refo/scl/sck pic18f4xk80 pic18lf4xk80 ra3/v ref +/an3 v ss rb1/an8/ctdin/int1 rb0/an10/flt0/int0 v ss rc4/sda/sdi rc5/sdo rc6/cantx/tx1/ck1/ccp3 rb6/pgc/kbi2 rb5/t0cki/t3cki/ccp5/kbi1 rb4/an9/ctpls/kbi0 16 20 21 29 30 31 37 38 41 39 34 44 43 42 40 36 35 rc7/canrx/rx1/dt1/ccp4 rd4/eccp1/p1a/psp4 rd5/p1b/psp5 rd6/tx2/ck2/p1c/psp6 rd7/rx2/dt2/p1d/psp7 v dd rb2/cantx/cted1/int2 n/c v dd osc1/clkin/ra7 osc2/clkout/ra6 re0/an5/rd re1/an6/c1out/wr re2/an7/c2out/cs rd0/c1ina/psp0 rd1/c1inb/psp1 rd3/c2inb/ctmui/psp3 rd2/c2ina/psp2 n/c n/c n/c
pic18f66k80 family ds39977d-page 8 ? 2011 microchip technology inc. pin diagrams (continued) 44-pin qfn (1) note 1: for the qfn package, it is recommended that the bottom pad be connected to v ss . ra1/an1/c1inc rb3/canrx/cted2/int3 ra2/v ref -/an2/c2inc v ddcore /v cap ra5/an4/hlvdin/t1cki/ss 1 2 3 4 7 5 6 33 32 19 18 15 17 28 27 26 25 24 23 22 8 9 10 11 12 13 14 ra0/cv ref /an0/ulpwu mclr /re3 rb7/pgd/t3g/kbi3 rc0/sosco/sclki rc1/sosci rc2/t1g/ccp2 rc3/refo/scl/sck pic18f4xk80 pic18lf4xk80 ra3/v ref +/an3 v ss rb1/an8/ctdin/int1 rb0/an10/flt0/int0 v ss rc4/sda/sdi rc5/sdo rc6/cantx/tx1/ck1/ccp3 rb6/pgc/kbi2 rb5/t0cki/t3cki/ccp5/kbi1 rb4/an9/ctpls/kbi0 16 20 21 29 30 31 37 38 41 39 34 44 43 42 40 36 35 rc7/canrx/rx1/dt1/ccp4 rd4/eccp1/p1a/psp4 rd5/p1b/psp5 rd6/tx2/ck2/p1c/psp6 rd7/rx2/dt2/p1d/psp7 v dd rb2/cantx/cted1/int2 n/c v dd osc1/clkin/ra7 osc2/clkout/ra6 re0/an5/rd re1/an6/c1out/wr re2/an7/c2out/cs rd0/c1ina/psp0 rd1/c1inb/psp1 rd3/c2inb/ctmui/psp3 rd2/c2ina/psp2 n/c n/c n/c
? 2011 microchip technology inc. ds39977d-page 9 pic18f66k80 family pin diagrams (continued) 64-pin qfn (1) /tqfp ra1/an1/c1inc rb3/canrx/cted2/int3 ra2/v ref -/an2/c2inc ra5/an4/hlvdin/t1cki/ss 1 2 3 4 7 5 6 43 42 24 23 20 22 38 37 36 35 34 33 27 8 9 10 11 17 18 19 ra0/cv ref /an0/ulpwu mclr /re3 rc0/sosco/sclki rc1/sosci rc2/t1g/ccp2 rc3/refo/scl/sck pic18f6xk80 pic18lf6xk80 ra3/v ref +/an3 v ss rb1/an8/ctdin/int1 rb0/an10/flt0/int0 rc4/sda/sdi rc5/sdo rc6/ccp3 rb6/pgc/kbi2 rb5/t0cki/t3cki/ccp5/kbi1 rb4/an9/ctpls/kbi0 21 25 26 39 40 41 57 58 61 59 54 64 63 62 60 56 55 rc7/ccp4 rd4/eccp1/p1a/psp4 rd5/p1b/psp5 rd6/p1c/psp6 rd7/p1d/psp7 av dd rb2/cantx/cted1/int2 osc1/clkin/ra7 osc2/clkout/ra6 re0/an5/rd re1/an6/c1out/wr re2/an7/c2out/cs rd0/c1ina/psp0 rd1/c1inb/psp1 rd3/c2inb/ctmui/psp3 rd2/c2ina/psp2 rf0/mdmin 12 13 14 15 16 29 28 32 30 31 48 47 44 45 46 52 53 49 51 50 rg0/rx1/dt1 rg1/cantx2 v dd rg2/t3cki rg3/tx1/ck1 rg4/t0cki rf1 re5/cantx v dd v ss re4/canrx v ddcore /v cap rf2/mdcin1 rf3 a vdd v dd a vss v ss rf4/mdcin2 rf5 rf6/mdout rf7 v ss v dd re6/rx2/dt2 re7/tx2/ck2 rb7/pgd/t3g/kbi3 note 1: for the qfn package, it is recommended that the bottom pad be connected to v ss .
pic18f66k80 family ds39977d-page 10 ? 2011 microchip technology inc. table of contents 1.0 device overview ............................................................................................................. ........................................................... 13 2.0 guidelines for getting started with pic18fxxkxx microcontrollers ............................................................ ............................. 47 3.0 oscillator configurations .................................... ............................................................... ......................................................... 53 4.0 power-managed modes ......................................................................................................... .................................................... 67 5.0 reset ....................................................................................................................... ................................................................... 81 6.0 memory organization ......................................................................................................... ...................................................... 105 7.0 flash program memory........................................................................................................ .................................................... 133 8.0 data eeprom memory .......................................................................................................... ................................................. 143 9.0 8 x 8 hardware multiplier................................................................................................... ....................................................... 149 10.0 interrupts ................................................................................................................. ................................................................. 151 11.0 i/o ports .................................................................................................................. ................................................................. 175 12.0 data signal modulator ...................................................................................................... ........................................................ 199 13.0 timer0 module .............................................................................................................. ........................................................... 209 14.0 timer1 module .............................................................................................................. ........................................................... 213 15.0 timer2 module .............................................................................................................. ........................................................... 225 16.0 timer3 module .............................................................................................................. ........................................................... 227 17.0 timer4 modules............................................................................................................. ........................................................... 237 18.0 charge time measurement unit (ctmu) ........................................................................................ ........................................ 239 19.0 capture/compare/pwm (ccp) modules .......................................................................................... ....................................... 257 20.0 enhanced capture/compare/pwm (eccp) module................................................................................. ............................... 269 21.0 master synchronous serial port (mssp) module ............................................................................... ..................................... 291 22.0 enhanced universal synchronous asynchronous receiver transmitter (eusart) .................................................. ............. 337 23.0 12-bit analog-to-digital converter (a/d) module ............................................................................ ......................................... 361 24.0 comparator module.......................................................................................................... ........................................................ 375 25.0 comparator voltage reference module ........................................................................................ ........................................... 383 26.0 high/low-voltage detect (hlvd)............................................................................................. ................................................ 387 27.0 ecan module................................................................................................................ ........................................................... 393 28.0 special features of the cpu ................................................................................................ .................................................... 459 29.0 instruction set summary .................................................................................................... ...................................................... 485 30.0 development support........................................................................................................ ....................................................... 535 31.0 electrical characteristics ................................................................................................. ......................................................... 539 32.0 packaging information...................................................................................................... ........................................................ 587 appendix a: revision history................................................................................................... .......................................................... 607 appendix b: migration to pic18f66k80 family.................................................................................... ............................................. 607 index .......................................................................................................................... ....................................................................... 609 the microchip web site ......................................................................................................... ............................................................ 623 customer change notification service ........................................................................................... ................................................... 623 customer support ............................................................................................................... ............................................................... 623 reader response ................................................................................................................ .............................................................. 624 product identification system.................................................................................................. ........................................................... 625
? 2011 microchip technology inc. ds39977d-page 11 pic18f66k80 family to our valued customers it is our intention to provide our valued customers with the best documentation possible to ensure successful use of your micro chip products. to this end, we will continue to improve our publications to better suit your needs. our publications will be refined and enhanced as new volumes and updates are introduced. if you have any questions or comments regar ding this publication, please contact the marketing communications department via e-mail at docerrors@microchip.com or fax the reader response form in the back of this data sheet to (480) 792-4150. we welcome your feedback. most current data sheet to obtain the most up-to-date version of this data s heet, please register at our worldwide web site at: http://www.microchip.com you can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page . the last character of the literature number is the vers ion number, (e.g., ds30000a is version a of document ds30000). errata an errata sheet, describing minor operational differences fr om the data sheet and recommended workarounds, may exist for curren t devices. as device/documentation issues become known to us, we will publish an errata sheet. the errata will specify the revisi on of silicon and revision of document to which it applies. to determine if an errata sheet exists for a particular device, please check with one of the following: ? microchip?s worldwide web site; http://www.microchip.com ? your local microchip sales office (see last page) when contacting a sales office, please specify which device, re vision of silicon and data sheet (include literature number) you are using. customer notification system register on our web site at www.microchip.com to receive the most current information on all of our products.
pic18f66k80 family ds39977d-page 12 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds39977d-page 13 pic18f66k80 family 1.0 device overview this document contains device-specific information for the following devices: this family combines the traditional advantages of all pic18 microcontrollers ? namely, high computational performance and a rich feature set ? with an extremely competitive price point. these features make the pic18f66k80 family a logical choice for many high-performance applications where price is a primary consideration. 1.1 core features 1.1.1 nanowatt technology all of the devices in the pic18f66k80 family incorpo- rate a range of features that can significantly reduce power consumption during operation. key items include: ? alternate run modes: by clocking the controller from the timer1 source or the internal rc oscilla- tor, power consumption during code execution can be reduced. ? multiple idle modes: the controller can also run with its cpu core disabled but the peripherals still active. in these states, power consumption can be reduced even further. ? on-the-fly mode switching: the power-managed modes are invoked by user code during operation, allowing the user to incorporate power-saving ideas into their application?s software design. ? nanowatt xlp: an extra low-power bor and low-power watchdog timer 1.1.2 oscillator options and features all of the devices in the pic18f66k80 family offer different oscillator options, allowing users a range of choices in developing application hardware. these include: ? external resistor/capacitor (rc); ra6 available ? external resistor/capacitor with clock out (rcio) ? three external clock modes: - external clock (ec); ra6 available - external clock with clock out (ecio) - external crystal (xt, hs, lp) ? a phase lock loop (pll) frequency multiplier, available to the external oscillator modes which allows clock speeds of up to 64 mhz. pll can also be used with the internal oscillator. ? an internal oscillator block that provides a 16 mhz clock (2% accuracy) and an intosc source (approximately 31 khz, stable over temperature and v dd ) - operates as hf-intosc or mf-intosc when block is selected for 16 mhz or 500 khz - frees the two oscillator pins for use as additional general purpose i/o the internal oscillator block provides a stable reference source that gives the family additional features for robust operation: ? fail-safe clock monitor: this option constantly monitors the main clock source against a reference signal provided by the internal oscillator. if a clock failure occurs, the controller is switched to the internal oscillator, allowing for continued low-speed operation or a safe application shutdown. ? two-speed start-up: this option allows the internal oscillator to serve as the clock source from power-on reset, or wake-up from sleep mode, until the primary clock source is available. 1.1.3 memory options the pic18f66k80 family provides ample room for application code, from 32 kbytes to 64 kbytes of code space. the flash cells for program memory are rated to last up to 10,000 erase/write cycles. data retention without refresh is conservatively estimated to be greater than 20 years. the flash program memory is readable and writable. during normal operation, the pic18f66k80 family also provides plenty of room for dynamic application data with up to 3.6 kbytes of data ram. 1.1.4 extended instruction set the pic18f66k80 family implements the optional extension to the pic18 instruction set, adding eight new instructions and an indexed addressing mode. enabled as a device configuration option, the extension has been specifically designed to optimize re-entrant application code originally developed in high-level languages, such as ?c?. ? pic18f25k80 ? pic18lf25k80 ? pic18f26k80 ? pic18lf26k80 ? pic18f45k80 ? pic18lf45k80 ? pic18f46k80 ? pic18lf46k80 ? pic18f65k80 ? pic18lf65k80 ? pic18f66k80 ? pic18lf66k80
pic18f66k80 family ds39977d-page 14 ? 2011 microchip technology inc. 1.1.5 easy migration regardless of the memory size, all devices share the same rich set of peripherals, allowing for a smooth migration path as applications grow and evolve. the consistent pinout scheme used throughout the entire family also aids in migrating to the next larger device. this is true when moving between the 28-pin, 40-pin, 44-pin and 64-pin members, or even jumping from smaller to larger memory devices. the pic18f66k80 family is also largely pin compatible with other pic18 families, such as the pic18f4580, pic18f4680, and pic18f8680 families of microcon- trollers with an ecan module. this allows a new dimension to the evolution of applications, allowing developers to select different price points within microchip?s pic18 portfolio, while maintaining a similar feature set. 1.2 other special features ? communications: the pic18f66k80 family incor- porates a range of serial communication peripherals including two enhanced usart that support lin/j2602, one master ssp module capable of both spi and i 2 c? (master and slave) modes of operation and an enhanced can module. ? ccp modules: pic18f66k80 family devices incorporate four capture/compare/pwm (ccp) modules. up to four different time bases can be used to perform several different operations at once. ? eccp modules: the pic18f66k80 family has one enhanced ccp (eccp) module to maximize flexibility in control applications: - up to four different time bases for performing several different operations at once - up to four pwm outputs - other beneficial features, such as polarity selection, programmable dead time, auto-shutdown and restart, and half-bridge and full-bridge output modes ? 12-bit a/d converter: the pic18f66k80 family has a differential adc. it incorporates program- mable acquisition time, allowing for a channel to be selected and a conversion to be initiated without waiting for a sampling period, and thus, reducing code overhead. ? charge time measurement unit (ctmu): the ctmu is a flexible analog module that provides accurate differential time measurement between pulse sources, as well as asynchronous pulse generation. together with other on-chip analog modules, the ctmu can precisely measure time, measure capacitance or relative changes in capacitance, or generate output pulses that are independent of the system clock. ? lp watchdog timer (wdt): this enhanced version incorporates a 22-bit prescaler, allowing an extended time-out range that is stable across operating voltage and temperature. see section 31.0 ?electrical characteristics? for time-out periods. 1.3 details on individual family members devices in the pic18f66k80 family are available in 28-pin, 40/44-pin and 64-pin packages. block diagrams for each package are shown in figure 1-1 , figure 1-2 and figure 1-3 , respectively. the devices are differentiated from each other in these ways: ? flash program memory: - pic18fx5k80 (pic18f25k80, pic18f45k80 and pic18f45k80) ? 32 kbytes - pic18fx6k80 (pic18f26k80, pic18f46k80 and pic18f66k80) ? 64 kbytes ? i/o ports: - pic18f2xk80 (28-pin devices) ? three bidirectional ports - pic18f4xk80 (40/44-pin devices) ? five bidirectional ports - pic18f6xk80 (64-pin devices) ? seven bidirectional ports all other features for devices in this family are identical. these are summarized in table 1-1 , tab l e 1 - 2 and table 1-3 . the pinouts for all devices are listed in ta b l e 1 - 4 , table 1-5 and ta bl e 1 - 6 .
? 2011 microchip technology inc. ds39977d-page 15 pic18f66k80 family table 1-1: device features for th e pic18f2xk80 (28-pin devices) features pic18f25k80 pic18f26k80 operating frequency dc ? 64 mhz program memory (bytes) 32k 64k program memory (instructions) 16,384 32,768 data memory (bytes) 3.6k interrupt sources 31 i/o ports ports a, b, c parallel communications parallel slave port (psp) timers five comparators two ctmu yes capture/compare/pwm (ccp) modules four enhanced ccp (eccp) modules one serial communications one mssp and two enhanced usarts (eusart) 12-bit analog-to-digital module eight input channels resets (and delays) por, bor, reset instruction, stack full, stack underflow, mclr , wdt (pwrt, ost) instruction set 75 instructions, 83 with extended instruction set enabled packages 28-pin qfn-s, soic, spdip and ssop table 1-2: device features for the pic18f4xk80 (40/44-pin devices) features pic18f45k80 pic18f46k80 operating frequency dc ? 64 mhz program memory (bytes) 32k 64k program memory (instructions) 16,384 32,768 data memory (bytes) 3.6k interrupt sources 32 i/o ports ports a, b, c, d, e parallel communications parallel slave port (psp) timers five comparators two ctmu yes capture/compare/pwm (ccp) modules four enhanced ccp (eccp) modules one serial communications one mssp and two enhanced usarts (eusart) 12-bit analog-to-digital module eleven input channels resets (and delays) por, bor, reset instruction, stack full, stack underflow, mclr , wdt (pwrt, ost) instruction set 75 instructions, 83 with extended instruction set enabled packages 40-pin pdip and 44-pin qfn and tqfp
pic18f66k80 family ds39977d-page 16 ? 2011 microchip technology inc. table 1-3: device features for th e pic18f6xk80 (64-pin devices) features pic18f65k80 pic18f66k80 operating frequency dc ? 64 mhz program memory (bytes) 32k 64k program memory (instructions) 16,384 32,768 data memory (bytes) 3.6k interrupt sources 32 i/o ports ports a, b, c, d, e, f, g parallel communications parallel slave port (psp) timers five comparators two ctmu yes capture/compare/pwm (ccp) modules four enhanced ccp (eccp) modules one dsm yes yes serial communications one mssp and two enhanced usarts (eusart) 12-bit analog-to-digital module eleven input channels resets (and delays) por, bor, reset instruction, stack full, stack underflow, mclr , wdt (pwrt, ost) instruction set 75 instructions, 83 with extended instruction set enabled packages 64-pin qfn and tqfp
? 2011 microchip technology inc. ds39977d-page 17 pic18f66k80 family figure 1-1: pic18f2xk80 (28-pin) block diagram instruction decode and control data latch data memory (2/4 kbytes) address latch data address<12> 12 access bsr fsr0 fsr1 fsr2 inc/dec logic address 4 12 4 pch pcl pclath 8 31-level stack program counter prodl prodh 8 x 8 multiply 8 bitop 8 8 alu<8> address latch program memory data latch 20 8 8 table pointer<21> inc/dec logic 21 8 data bus<8> table latch 8 ir 12 3 pclatu pcu note 1: see table 1-4 for i/o port pin descriptions. 2: ra6 and ra7 are only available as digital i/o in select oscillator modes. for more information, see section 3.0 ?oscillator configurations? . 3: re3 is only available when the mclre configuration bit is cleared (mclre = 0 ). eusart1 comparator ctmu timer1 adc 12-bit w instruction bus<16> stkptr bank 8 state machine control signals decode 8 8 eusart2 rom latch portc rc0:rc7 (1) portb rb0:rb7 (1) osc1/clki osc2/clko v dd , timing generation v ss mclr power-up timer oscillator start-up timer power-on reset watchdog timer bor and lvd precision reference band gap intosc oscillator regulator voltage v ddcore /v cap 16 mhz oscillator timer0 timer 2/4 timer 3 1/2 ccp2/3/4/5 eccp1 porta ra0:ra3 ra5:ra7 (1,2) porte re3 (1,3) ecan mssp
pic18f66k80 family ds39977d-page 18 ? 2011 microchip technology inc. figure 1-2: pic18f4xk80 (40/44-pin) block diagram instruction decode and control data latch data memory (2/4 kbytes) address latch data address<12> 12 access bsr fsr0 fsr1 fsr2 inc/dec logic address 4 12 4 pch pcl pclath 8 31-level stack program counter prodl prodh 8 x 8 multiply 8 bitop 8 8 alu<8> address latch program memory data latch 20 8 8 table pointer<21> inc/dec logic 21 8 data bus<8> table latch 8 ir 12 3 pclatu pcu note 1: see table 1-5 for i/o port pin descriptions. 2: ra6 and ra7 are only available as digital i/o in select oscillator modes. for more information, see section 3.0 ?oscillator configurations? . 3: re3 is only available when the mclre configuration bit is cleared (mclre = 0 ). eusart1 comparator ctmu timer1 adc 12-bit w instruction bus<16> stkptr bank 8 state machine control signals decode 8 8 eusart2 rom latch portc portd rc0:rc7 (1) rd0:rd7 (1) portb rb0:rb7 (1) osc1/clki osc2/clko v dd , timing generation v ss mclr power-up timer oscillator start-up timer power-on reset watchdog timer bor and lvd precision reference band gap intosc oscillator regulator voltage v ddcore /v cap 16 mhz oscillator timer0 2/3/4/5 timer2/4 timer3 1/2 ccp eccp1 porta ra0:ra3 ra5:ra7 (1,2) porte re0:re3 (1,3) ecan psp mssp
? 2011 microchip technology inc. ds39977d-page 19 pic18f66k80 family figure 1-3: pic18f6xk80 (64-pin) block diagram instruction decode and control data latch data memory (2/4 kbytes) address latch data address<12> 12 access bsr fsr0 fsr1 fsr2 inc/dec logic address 4 12 4 pch pcl pclath 8 31-level stack program counter prodl prodh 8 x 8 multiply 8 bitop 8 8 alu<8> address latch program memory data latch 20 8 8 table pointer<21> inc/dec logic 21 8 data bus<8> table latch 8 ir 12 3 pclatu pcu note 1: see ta b l e 1 - 6 for i/o port pin descriptions. 2: ra6 and ra7 are only available as digital i/o in select oscillator modes. for more information, see section 3.0 ?oscillator configurations? . 3: re3 is only available when the mclre configuration bit is cleared (mclre = 0 ). eusart1 comparator ctmu timer1 adc 12-bit w instruction bus<16> stkptr bank 8 state machine control signals decode 8 8 eusart2 rom latch portc portd portf portg rc0:rc7 (1) rd0:rd7 (1) rf0:rf7 (1) rg0:rg4 (1) portb rb0:rb7 (1) osc1/clki osc2/clko v dd , timing generation v ss mclr power-up timer oscillator start-up timer power-on reset watchdog timer bor and lvd precision reference band gap intosc oscillator regulator voltage v ddcore /v cap 16 mhz oscillator timer0 timer2/4 timer3 1/2 ccp2/3/4/5 eccp1 porta ra0:ra3 ra5:ra7 (1,2) porte re0:re7 (1,3) ecan dsm psp mssp
pic18f66k80 family ds39977d-page 20 ? 2011 microchip technology inc. table 1-4: pic18f2xk8 0 i/o descriptions pin name pin number pin type buffer type description qfn ssop/ spdip/ soic mclr /re3 26 1 mclr i st master clear (input) or programming voltage (input).this pin is an active-low reset to the device. re3 i st general purpose, input only pin. osc1/clkin/ra7 6 9 osc1 i st oscillator crystal input. clkin i cmos external clock source input. always associated with pin function, osc1. (see related osc1/clki, osc2/clko pins.) ra7 i/o st/ cmos general purpose i/o pin. osc2/clkout/ra6 7 10 osc2 o ? oscillator crystal output. connects to crystal or resonator in crystal oscillator mode. clkout o ? in certain oscillator modes, osc2 pin outputs clko, which has 1/4 the frequency of osc1 and denotes the instruction cycle rate. ra6 i/o st/ cmos general purpose i/o pin. legend: cmos = cmos compatible input or output i 2 c? = i 2 c/smbus input buffer st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
? 2011 microchip technology inc. ds39977d-page 21 pic18f66k80 family porta is a bidirectional i/o port. ra0/cv ref /an0/ulpwu 27 2 ra0 i/o st/ cmos general purpose i/o pin. cv ref o analog comparator reference voltage output. an0 i analog analog input 0. ulpwu i analog ultra low-power wake-up input. ra1/an1 28 3 ra1 i/o st/ cmos digital i/o. an1 i analog analog input 1. ra2/v ref -/an2 1 4 ra2 i/o st/ cmos digital i/o. v ref - i analog a/d reference voltage (low) input. an2 i analog analog input 2. ra3/v ref +/an3 2 5 ra3 i/o st/ cmos digital i/o. v ref + i analog a/d reference voltage (high) input. an3 i analog analog input 3. ra5/an4/c2inb/hlvdin/ t1cki/ss /ctmui 47 ra5 i/o st/ cmos digital i/o. an4 i analog analog input 4. c2inb i analog comparator 2 input b. hlvdin i analog high/low-voltage detect input. t1cki i st timer1 clock input. ss i st spi slave select input. ctmui ctmu pulse generator charger for the c2inb. table 1-4: pic18f2xk80 i/o descriptions (continued) pin name pin number pin type buffer type description qfn ssop/ spdip/ soic legend: cmos = cmos compatible input or output i 2 c? = i 2 c/smbus input buffer st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
pic18f66k80 family ds39977d-page 22 ? 2011 microchip technology inc. portb is a bidirectional i/o port. rb0/an10/c1ina/flt0/ int0 18 21 rb0 i/o st/ cmos digital i/o. an10 i analog analog input 10. c1ina i analog comparator 1 input a. flt0 i st enhanced pwm fault input for eccp1. int0 i st external interrupt 0. rb1/an8/c1inb/p1b/ ctdin/int1 19 22 rb1 i/o st/ cmos digital i/o. an8 i analog analog input 8. c1inb i analog comparator 1 input b. p1b o cmos enhanced pwm1 output b. ctdin i st ctmu pulse delay input. int1 i st external interrupt 1. rb2/cantx/c1out/ p1c/cted1/int2 20 23 rb2 i/o st/ cmos digital i/o. cantx o cmos can bus tx. c1out o cmos comparator 1 output. p1c o cmos enhanced pwm1 output c. cted1 i st ctmu edge 1 input. int2 i st external interrupt 2. rb3/canrx/c2out/ p1d/cted2/int3 21 24 rb3 i/o st/ cmos digital i/o. canrx i st can bus rx. c2out o cmos comparator 2 output. p1d o cmos enhanced pwm1 output d. cted2 i st ctmu edge 2 input. int3 i st external interrupt 3. table 1-4: pic18f2xk80 i/o descriptions (continued) pin name pin number pin type buffer type description qfn ssop/ spdip/ soic legend: cmos = cmos compatible input or output i 2 c? = i 2 c/smbus input buffer st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
? 2011 microchip technology inc. ds39977d-page 23 pic18f66k80 family rb4/an9/c2ina/eccp1/ p1a/ctpls/kbi0 22 25 rb4 i/o st/ cmos digital i/o. an9 i analog analog input 9. c2ina i analog comparator 2 input a. eccp1 i/o st capture 1 input/compare 1 output/pwm1 output. p1a o cmos enhanced pwm1 output a. ctpls o st ctmu pulse generator output. kbi0 i st interrupt-on-change pin. rb5/t0cki/t3cki/ccp5/ kbi1 23 26 rb5 i/o st/ cmos digital i/o. t0cki i st timer0 external clock input. t3cki i st timer3 external clock input. ccp5 i/o st/ cmos capture 5 input/compare 5 output/pwm5 output. kbi1 i st interrupt-on-change pin. rb6/pgc/tx2/ck2/kbi2 24 27 rb6 i/o st/ cmos digital i/o. pgc i st in-circuit debugger and icsp? programming clock input pin. tx2 o cmos eusart asynchronous transmit. ck2 i/o st eusart synchronous clock (see related rx2/dt2). kbi2 i st interrupt-on-change pin. rb7/pgd/t3g/rx2/dt2/ kbi3 25 28 rb7 i/o st/ cmos digital i/o. pgd i/o st in-circuit debugger and icsp programming data pin. t3g i st timer3 external clock gate input. rx2 i st eusart asynchronous receive. dt2 i/o st eusart synchronous data (see related tx2/ck2). kbi3 i st interrupt-on-change pin. table 1-4: pic18f2xk80 i/o descriptions (continued) pin name pin number pin type buffer type description qfn ssop/ spdip/ soic legend: cmos = cmos compatible input or output i 2 c? = i 2 c/smbus input buffer st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
pic18f66k80 family ds39977d-page 24 ? 2011 microchip technology inc. portc is a bidirectional i/o port. rc0/sosco/sclki 8 11 rc0 i/o st/ cmos digital i/o. sosco i st timer1 oscillator output. sclki i st digital sosc input. rc1/sosci 9 12 rc1 i/o st/ cmos digital i/o. sosci i cmos sosc oscillator input. rc2/t1g/ccp2 10 13 rc2 i/o st/ cmos digital i/o. t1g i st timer1 external clock gate input. ccp2 i/o st capture 2 input/compare 2 output/pwm2 output. rc3/refo/scl/sck 11 14 rc3 i/o st/ cmos digital i/o. refo o ? reference clock out. scl i/o i 2 c synchronous serial clock input/output for i 2 c mode. sck i/o st synchronous serial clock input/output for spi mode. rc4/sda/sdi 12 15 rc4 i/o st/ cmos digital i/o. sda i/o i 2 ci 2 c data input/output. sdi i st spi data in. rc5/sdo 13 16 rc5 i/o st/ cmos digital i/o. sdo o cmos spi data out. rc6/cantx/tx1/ck1/ ccp3 14 17 rc6 i/o st/ cmos digital i/o. cantx o cmos can bus tx. tx1 o cmos eusart asynchronous transmit. ck1 i/o st eusart synchronous clock. (see related rx1/dt1.) ccp3 i/o st/ cmos capture 3 input/compare 3 output/pwm3 output. table 1-4: pic18f2xk80 i/o descriptions (continued) pin name pin number pin type buffer type description qfn ssop/ spdip/ soic legend: cmos = cmos compatible input or output i 2 c? = i 2 c/smbus input buffer st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
? 2011 microchip technology inc. ds39977d-page 25 pic18f66k80 family rc7/canrx/rx1/dt1/ ccp4 15 18 rc7 i/o st/ cmos digital i/o. canrx i st can bus rx. rx1 i st eusart asynchronous receive. dt1 i/o st eusart synchronous data (see related tx2/ck2). ccp4 i/o st cmos capture 4 input/compare 4 output/pwm4 output. v ss 58p v ss ground reference for logic and i/o pins. v ss 16 19 v ss ground reference for logic and i/o pins. v ddcore /v cap 36p v ddcore external filter capacitor connection. v cap external filter capacitor connection v dd 17 20 p v dd positive supply for logic and i/o pins. table 1-4: pic18f2xk80 i/o descriptions (continued) pin name pin number pin type buffer type description qfn ssop/ spdip/ soic legend: cmos = cmos compatible input or output i 2 c? = i 2 c/smbus input buffer st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
pic18f66k80 family ds39977d-page 26 ? 2011 microchip technology inc. table 1-5: pic18f4xk80 pi nout i/o descriptions pin name pin number pin type buffer type description pdip qfn/ tqfp mclr /re3 1 18 mclr i st master clear (input) or programming voltage (input).this pin is an active-low reset to the device. re3 i st general purpose, input only pin. osc1/clkin/ra7 13 30 osc1 i st oscillator crystal input. clkin i cmos external clock source input. always associated with pin function, osc1. (see related osc1/clki, osc2/clko pins. ra7 i/o st/ cmos general purpose i/o pin. osc2/clkout/ra6 14 31 osc2 o ? oscillator crystal output. connects to crystal or resonator in crystal oscillator mode. clkout o ? in certain oscillator modes, osc2 pin outputs clko, which has 1/4 the frequency of osc1 and denotes the instruction cycle rate. ra6 i/o st/ cmos general purpose i/o pin. legend: i 2 c? = i 2 c/smbus input buffer cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
? 2011 microchip technology inc. ds39977d-page 27 pic18f66k80 family porta is a bidirectional i/o port. ra0/cv ref /an0/ulpwu 2 19 ra0 i/o st/ cmos general purpose i/o pin. cv ref o analog comparator reference voltage output. an0 i analog analog input 0. ulpwu i analog ultra low-power wake-up input. ra1/an1/c1inc 3 20 ra1 i/o st/ cmos digital i/o. an1 i analog analog input 1. c1inc i analog comparator 1 input c. ra2/v ref -/an2/c2inc 4 21 ra2 i/o st/ cmos digital i/o. v ref - i analog a/d reference voltage (low) input. an2 i analog analog input 2. c2inc i analog comparator 2 input c. ra3/v ref +/an3 5 22 ra3 i/o st/ cmos digital i/o. v ref + i analog a/d reference voltage (high) input. an3 i analog analog input 3. ra5/an4/hlvdin/t1cki/ ss 724 ra5 i/o st/ cmos digital i/o. an4 i analog analog input 4. hlvdin i analog high/low-voltage detect input. t1cki i st timer1 clock input. ss i st spi slave select input. table 1-5: pic18f4xk8 0 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pdip qfn/ tqfp legend: i 2 c? = i 2 c/smbus input buffer cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
pic18f66k80 family ds39977d-page 28 ? 2011 microchip technology inc. portb is a bidirectional i/o port. rb0/an10/flt0/int0 33 8 rb0 i/o st/ cmos digital i/o. an10 i analog analog input 10. flt0 i st enhanced pwm fault input for eccp1. int0 i st external interrupt 0. rb1/an8/ctdin/int1 34 9 rb1 i/o st/ cmos digital i/o. an8 i analog analog input 8. ctdin i st ctmu pulse delay input. int1 i st external interrupt 1. rb2/cantx/cted1/ int2 35 10 rb2 i/o st/ cmos digital i/o. cantx o cmos can bus tx. cted1 i st ctmu edge 1 input. int2 i st external interrupt 2. rb3/canrx/cted2/ int3 36 11 rb3 i/o st/ cmos digital i/o. canrx i st can bus rx. cted2 i st ctmu edge 2 input. int3 i st external interrupt 3. rb4/an9/ctpls/kbi0 37 14 rb4 i/o st/ cmos digital i/o. an9 i analog analog input 9. ctpls o st ctmu pulse generator output. kbi0 i st interrupt-on-change pin. rb5/t0cki/t3cki/ccp5/ kbi1 38 15 rb5 i/o st/ cmos digital i/o. t0cki i st timer0 external clock input. t3cki i st timer3 external clock input. ccp5 i/o st capture 5 input/compare 5 output/pwm5 output. kbi1 i st interrupt-on-change pin. table 1-5: pic18f4xk8 0 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pdip qfn/ tqfp legend: i 2 c? = i 2 c/smbus input buffer cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
? 2011 microchip technology inc. ds39977d-page 29 pic18f66k80 family rb6/pgc/kbi2 39 16 rb6 i/o st/ cmos digital i/o. pgc i st in-circuit debugger and icsp? programming clock input pin. kbi2 i st interrupt-on-change pin. rb7/pgd/t3g/kbi3 40 17 rb7 i/o st/ cmos digital i/o. pgd i/o st in-circuit debugger and icsp? programming data pin. t3g i st timer3 external clock gate input. kbi3 i st interrupt-on-change pin. table 1-5: pic18f4xk8 0 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pdip qfn/ tqfp legend: i 2 c? = i 2 c/smbus input buffer cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
pic18f66k80 family ds39977d-page 30 ? 2011 microchip technology inc. portc is a bidirectional i/o port. rc0/sosco/sclki 15 32 rc0 i/o st/ cmos digital i/o. sosco i st sosc oscillator output. sclki i st digital sosc input. rc1/sosci 16 35 rc1 i/o st/ cmos digital i/o. sosci i cmos sosc oscillator input. rc2/t1g/ccp2 17 36 rc2 i/o st/ cmos digital i/o. t1g i st timer1 external clock gate input. ccp2 i/o st/ cmos capture 2 input/compare 2 output/pwm2 output. rc3/refo/scl/sck 18 37 rc3 i/o st/ cmos digital i/o. refo o cmos reference clock out. scl i/o i 2 c synchronous serial clock input/output for i 2 c mode. sck i/o st synchronous serial clock input/output for spi mode. rc4/sda/sdi 23 42 rc4 i/o st/ cmos digital i/o. sda i/o i 2 ci 2 c data input/output. sdi i st spi data in. rc5/sdo 24 43 rc5 i/o st/ cmos digital i/o. sdo o cmos spi data out. rc6/cantx/tx1/ck1/ ccp3 25 44 rc6 i/o st/ cmos digital i/o. cantx o cmos can bus tx. tx1 o cmos eusart synchronous transmit. ck1 i/o st eusart synchronous clock (see related rx2/dt2). ccp3 i/o st capture 3 input/compare 3 output/pwm3 output. table 1-5: pic18f4xk8 0 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pdip qfn/ tqfp legend: i 2 c? = i 2 c/smbus input buffer cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
? 2011 microchip technology inc. ds39977d-page 31 pic18f66k80 family rc7/canrx/rx1/dt1/ ccp4 26 1 rc7 i/o st/ cmos digital i/o. canrx i st can bus rx. rx1 i st eusart asynchronous receive. dt1 i/o st eusart synchronous data (see related tx2/ck2). ccp4 i/o st capture 4 input/compare 4 output/pwm4 output. table 1-5: pic18f4xk8 0 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pdip qfn/ tqfp legend: i 2 c? = i 2 c/smbus input buffer cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
pic18f66k80 family ds39977d-page 32 ? 2011 microchip technology inc. portd is a bidirectional i/o port. rd0/c1ina/psp0 19 38 rd0 i/o st/ cmos digital i/o. c1ina i analog comparator 1 input a. psp0 i/o st/ cmos parallel slave port data. rd1/c1inb/psp1 20 39 rd1 i/o st/ cmos digital i/o. c1inb i analog comparator 1 input b. psp1 i/o st/ cmos parallel slave port data. rd2/c2ina/psp2 21 40 rd2 i/o st/ cmos digital i/o. c2ina i analog comparator 2 input a. psp2 i/o st/ cmos parallel slave port data. rd3/c2inb/ctmui/ psp3 22 41 rd3 i/o st/ cmos digital i/o. c2inb i analog comparator 2 input b. ctmui ctmu pulse generator charger for the c2inb. psp3 i/o st/ cmos parallel slave port data. rd4/eccp1/p1a/psp4 27 2 rd4 i/o st/ cmos digital i/o. eccp1 i/o st capture 1 input/compare 1 output/pwm1 output. p1a o cmos enhanced pwm1 output a. psp4 i/o st/ cmos parallel slave port data. rd5/p1b/psp5 28 3 rd5 i/o st/ cmos digital i/o. p1b o cmos enhanced pwm1 output b. psp5 i/o st/ cmos parallel slave port data. table 1-5: pic18f4xk8 0 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pdip qfn/ tqfp legend: i 2 c? = i 2 c/smbus input buffer cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
? 2011 microchip technology inc. ds39977d-page 33 pic18f66k80 family rd6/tx2/ck2/p1c/psp6 29 4 rd6 i/o st/ cmos digital i/o. tx2 i st eusart asynchronous transmit. ck2 i/o st eusart synchronous clock (see related rx2/dt2). p1c o cmos enhanced pwm1 output c. psp6 i/o st/ cmos parallel slave port data. rd7/rx2/dt2/p1d/psp7 30 5 rd7 i/o st/ cmos digital i/o. rx2 i st eusart asynchronous receive. dt2 i/o st eusart synchronous data (see related tx2/ck2). p1d o cmos enhanced pwm1 output d. psp7 i/o st/ cmos parallel slave port data. re0/an5/rd 825 re0 i/o st/ cmos digital i/o. an5 i analog analog input 5. rd i st parallel slave port read strobe. re1/an6/c1out/wr 926 re1 i/o st/ cmos digital i/o. an6 i analog analog input 6. c1out o cmos comparator 1 output. wr i st parallel slave port write strobe. re2/an7/c2out/cs 10 27 re2 i/o st/ cmos digital i/o. an7 i analog analog input 7. c2out o cmos comparator 2 output. cs i st parallel slave port chip select. re3 see the mclr /re3 pin. table 1-5: pic18f4xk8 0 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pdip qfn/ tqfp legend: i 2 c? = i 2 c/smbus input buffer cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
pic18f66k80 family ds39977d-page 34 ? 2011 microchip technology inc. v ss 12 29 p v ss ground reference for logic and i/o pins. v ss 31 6 v ss ground reference for logic and i/o pins. v ddcore /v cap 623p v ddcore external filter capacitor connection v cap external filter capacitor connection v dd 11 28 p v dd positive supply for logic and i/o pins. v dd 327p v dd positive supply for logic and i/o pins. table 1-5: pic18f4xk8 0 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pdip qfn/ tqfp legend: i 2 c? = i 2 c/smbus input buffer cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
? 2011 microchip technology inc. ds39977d-page 35 pic18f66k80 family table 1-6: pic18f6xk80 pi nout i/o descriptions pin name pin num pin type buffer type description mclr /re3 28 mclr i st master clear (input) or programming voltage (input).this pin is an active-low reset to the device. re3 i st general purpose, input only pin. osc1/clkin/ra7 46 osc1 i st oscillator crystal input. clkin i cmos external clock source input. always associated with pin function, osc1. (see related osc1/clki, osc2/clko pins.) ra7 i/o st/ cmos general purpose i/o pin. osc2/clkout/ra6 47 osc2 o ? oscillator crystal output. connects to crystal or resonator in crystal oscillator mode. clkout o ? in certain oscillator modes, osc2 pin outputs clko, which has 1/4 the frequency of osc1 and denotes the instruction cycle rate. ra6 i/o st/ cmos general purpose i/o pin. legend: i 2 c? = i 2 c/smbus input buffer cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
pic18f66k80 family ds39977d-page 36 ? 2011 microchip technology inc. porta is a bidirectional i/o port. ra0/cv ref /an0/ ulpwu 29 ra0 i/o st/ cmos general purpose i/o pin. cv ref o analog comparator reference voltage output. an0 i analog analog input 0. ulpwu i analog ultra low-power wake-up input. ra1/an1/c1inc 30 ra1 i/o st/ cmos digital i/o. an1 i analog analog input 1. c1inc i analog comparator 1 input c. ra2/v ref -/an2/c2inc 31 ra2 i/o st/ cmos digital i/o. v ref - i analog a/d reference voltage (low) input. an2 i analog analog input 2. c2inc i analog comparator 2 input c. ra3/v ref +/an3 32 ra3 i/o st/ cmos digital i/o. v ref + i analog a/d reference voltage (high) input. an3 i analog analog input 3. ra5/an4/hlvdin/ t1cki/ss 34 ra5 i/o st/ cmos digital i/o. an4 i analog analog input 4. hlvdin i analog high/low-voltage detect input. t1cki i st timer1 clock input. ss i st spi slave select input. table 1-6: pic18f6xk8 0 pinout i/o descriptions (continued) pin name pin num pin type buffer type description legend: i 2 c? = i 2 c/smbus input buffer cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
? 2011 microchip technology inc. ds39977d-page 37 pic18f66k80 family portb is a bidirectional i/o port. rb0/an10/flt0/int0 13 rb0 i/o st/ cmos digital i/o. an10 i analog analog input 10. flt0 i st enhanced pwm fault input for eccp1. int0 i st external interrupt 0. rb1/an8/ctdin/int1 14 rb1 i/o st/ cmos digital i/o. an8 i analog analog input 8. ctdin i st ctmu pulse delay input. int1 i st external interrupt 1. rb2/cantx/cted1/ int2 15 rb2 i/o st/ cmos digital i/o. cantx o cmos can bus tx. cted1 i st ctmu edge 1 input. int2 i st external interrupt 2. rb3/canrx/cted2/ int3 16 rb3 i/o st/ cmos digital i/o. canrx i st can bus rx. cted2 i st ctmu edge 2 input. int3 i st external interrupt 3. rb4/an9/ctpls/kbi0 20 rb4 i/o st/ cmos digital i/o. an9 i analog analog input 9. ctpls o st ctmu pulse generator output. kbi0 i st interrupt-on-change pin. rb5/t0cki/t3cki/ccp5/ kbi1 21 rb5 i/o st/ cmos digital i/o. t0cki i st timer0 external clock input. t3cki i st timer3 external clock input. ccp5 i/o st/ cmos capture 5 input/compare 5 output/pwm5 output. kbi1 i st interrupt-on-change pin. table 1-6: pic18f6xk8 0 pinout i/o descriptions (continued) pin name pin num pin type buffer type description legend: i 2 c? = i 2 c/smbus input buffer cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
pic18f66k80 family ds39977d-page 38 ? 2011 microchip technology inc. rb6/pgc/kbi2 22 rb6 i/o st/ cmos digital i/o. pgc i st in-circuit debugger and icsp? programming clock input pin. kbi2 i st interrupt-on-change pin. rb7/pgd/t3g/kbi3 23 rb7 i/o st/ cmos digital i/o. pgd i/o st in-circuit debugger and icsp? programming data pin. t3g i st timer3 external clock gate input. kbi3 i st interrupt-on-change pin. table 1-6: pic18f6xk8 0 pinout i/o descriptions (continued) pin name pin num pin type buffer type description legend: i 2 c? = i 2 c/smbus input buffer cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
? 2011 microchip technology inc. ds39977d-page 39 pic18f66k80 family portc is a bidirectional i/o port. rc0/sosco/sclki 48 rc0 i/o st/ cmos digital i/o. sosco i st timer1 oscillator output. sclki i st digital sosc input. rc1/sosci 49 rc1 i/o st/ cmos digital i/o. sosci i cmos sosc oscillator input. rc2/t1g/ccp2 50 rc2 i/o st/ cmos digital i/o. t1g i st timer1 external clock gate input. ccp2 i/o st capture 2 input/compare 2 output/pwm2 output. rc3/refo/scl/sck 51 rc3 i/o st/ cmos digital i/o. refo o cmos reference clock out. scl i/o i 2 c synchronous serial clock input/output for i 2 c mode. sck i/o st synchronous serial clock input/output for spi mode. rc4/sda/sdi 62 rc4 i/o st/ cmos digital i/o. sda i/o i 2 ci 2 c data input/output. sdi i st spi data in. rc5/sdo 63 rc5 i/o st/ cmos digital i/o. sdo o cmos spi data out. rc6/ccp3 64 rc6 i/o st/ cmos digital i/o. ccp3 i/o st/ cmos capture 3 input/compare 3 output/pwm3 output. rc7/ccp4 1 rc7 i/o st/ cmos digital i/o. ccp4 i/o st/ cmos capture 4 input/compare 4 output/pwm4 output. table 1-6: pic18f6xk8 0 pinout i/o descriptions (continued) pin name pin num pin type buffer type description legend: i 2 c? = i 2 c/smbus input buffer cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
pic18f66k80 family ds39977d-page 40 ? 2011 microchip technology inc. portd is a bidirectional i/o port. rd0/c1ina/psp0 54 rd0 i/o st/ cmos digital i/o. c1ina i analog comparator 1 input a. psp0 i/o st/ cmos parallel slave port data. rd1/c1inb/psp1 55 rd1 i/o st/ cmos digital i/o. c1inb i analog comparator 1 input b. psp1 i/o st/ cmos parallel slave port data. rd2/c2ina/psp2 58 rd2 i/o st/ cmos digital i/o. c2ina i analog comparator 2 input a. psp2 i/o st/ cmos parallel slave port data. rd3/c2inb/ctmui/ psp3 59 rd3 i/o st/ cmos digital i/o. c2inb i analog comparator 2 input b. ctmui o cmos ctmu pulse generator charger for the c2inb. psp3 i/o st/ cmos parallel slave port data. rd4/eccp1/p1a/psp4 2 rd4 i/o st/ cmos digital i/o. eccp1 i/o st capture 1 input/compare 1 output/pwm1 output. p1a o cmos enhanced pwm1 output a. psp4 i/o st/ cmos parallel slave port data. rd5/p1b/psp5 3 rd5 i/o st/ cmos digital i/o. p1b o cmos enhanced pwm1 output b. psp5 i/o st/ cmos parallel slave port data. table 1-6: pic18f6xk8 0 pinout i/o descriptions (continued) pin name pin num pin type buffer type description legend: i 2 c? = i 2 c/smbus input buffer cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
? 2011 microchip technology inc. ds39977d-page 41 pic18f66k80 family rd6/p1c/psp6 4 rd6 i/o st/ cmos digital i/o. p1c o cmos enhanced pwm1 output c. psp6 i/o st/ cmos parallel slave port data. rd7/p1d/psp7 5 rd7 i/o st/ cmos digital i/o. p1d o cmos enhanced pwm1 output d. psp7 i/o st/ cmos parallel slave port data. table 1-6: pic18f6xk8 0 pinout i/o descriptions (continued) pin name pin num pin type buffer type description legend: i 2 c? = i 2 c/smbus input buffer cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
pic18f66k80 family ds39977d-page 42 ? 2011 microchip technology inc. porte is a bidirectional i/o port. re0/an5/rd 37 re0 i/o st/ cmos digital i/o. an5 i analog analog input 5. rd i st parallel slave port read strobe. re1/an6/c1out/wr 38 re1 i/o st/ cmos digital i/o. an6 i analog analog input 6. c1out o cmos comparator 1 output. wr i st parallel slave port write strobe. re2/an7/c2out/cs 39 re2 i/o st/ cmos digital i/o. an7 i analog analog input 7. c2out o cmos comparator 2 output. cs i st parallel slave port chip select. re3 see the mclr /re3 pin. re4/canrx 27 re4 i/o st/ cmos digital i/o. canrx i st can bus rx. re5/cantx 24 re5 i/o st/ cmos digital i/o. cantx o cmos can bus tx. re6/rx2/dt2 60 re6 i/o st/ cmos digital i/o. rx2 i st eusart asynchronous receive. dt2 i/o st eusart synchronous data (see related tx2/ck2). re7/tx2/ck2 61 re7 i/o st/ cmos digital i/o. tx2 o cmos eusart asynchronous transmit. ck2 i/o st eusart synchronous clock (see related rx2/dt2). table 1-6: pic18f6xk8 0 pinout i/o descriptions (continued) pin name pin num pin type buffer type description legend: i 2 c? = i 2 c/smbus input buffer cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
? 2011 microchip technology inc. ds39977d-page 43 pic18f66k80 family portf is a bidirectional i/o port. rf0/mdmin 17 rf0 i/o st/ cmos digital i/o. mdmin i cmos modulator source input. rf1 19 rf1 i/o st/ cmos digital i/o. rf2/mdcin1 35 rf2 i/o st/ cmos digital i/o. mdcin1 i st modulator carrier input 1. rf3 36 rf3 i/o st/ cmos digital i/o. rf4/mdcin2 44 rf4 i/o st/ cmos digital i/o. mdcin2 i st modulator carrier input 2. rf5 45 rf5 i/o st/ cmos digital i/o. rf6/mdout 52 rf6 i/o st/ cmos digital i/o. mdout o cmos modulator output. rf7 53 rf7 i/o st/ cmos digital i/o. table 1-6: pic18f6xk8 0 pinout i/o descriptions (continued) pin name pin num pin type buffer type description legend: i 2 c? = i 2 c/smbus input buffer cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
pic18f66k80 family ds39977d-page 44 ? 2011 microchip technology inc. portg is a bidirectional i/o port. rg0/rx1/dt1 6 rg0 i/o st/ cmos digital i/o. rx1 i st eusart asynchronous receive. dt1 i/o st eusart synchronous data (see related tx2/ck2). rg1/cantx2 7 rg1 i/o st/ cmos digital i/o. cantx2 o cmos can bus complimentary transmit output or can bus time clock. rg2/t3cki 11 rg2 i/o st/ cmos digital i/o. t3cki i st timer3 clock input. rg3/tx1/ck1 12 rg3 i/o st/ cmos digital i/o. tx1 o cmos eusart asynchronous transmit. ck1 i/o st eusart synchronous clock (see related rx2/dt2). rg4/t0cki 18 rg4 i/o st/ cmos digital i/o. t0cki i st timer0 external clock input. table 1-6: pic18f6xk8 0 pinout i/o descriptions (continued) pin name pin num pin type buffer type description legend: i 2 c? = i 2 c/smbus input buffer cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
? 2011 microchip technology inc. ds39977d-page 45 pic18f66k80 family v ss 8p v ss ground reference for logic and i/o pins. v ss 26 p v ss ground reference for logic and i/o pins. a vss 42 p a vss ground reference for analog modules. v ss 43 p v ss ground reference for logic and i/o pins. v ss 56 p v ss ground reference for logic and i/o pins. a vdd 9p a vdd positive supply for analog modules. v dd 10 p v dd positive supply for logic and i/o pins. v dd 25 p v dd positive supply for logic and i/o pins. v ddcore /v cap 33 p v ddcore external filter capacitor connection. v cap external filter capacitor connection. a vdd 40 p a vdd positive supply for analog modules. v dd 41 p v dd positive supply for logic and i/o pins. v dd 57 p v dd positive supply for logic and i/o pins. table 1-6: pic18f6xk8 0 pinout i/o descriptions (continued) pin name pin num pin type buffer type description legend: i 2 c? = i 2 c/smbus input buffer cmos = cmos compatible input or output st = schmitt trigger input with cmos levels analog = analog input i = input o = output p= power
pic18f66k80 family ds39977d-page 46 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds39977d-page 47 pic18f66k80 family 2.0 guidelines for getting started with pic18fxxkxx microcontrollers 2.1 basic connection requirements getting started with the pic18f66k80 family family of 8-bit microcontrollers requires attention to a minimal set of device pin connections before proceeding with development. the following pins must always be connected: ?all v dd and v ss pins (see section 2.2 ?power supply pins? ) ?all av dd and av ss pins, regardless of whether or not the analog device features are used (see section 2.2 ?power supply pins? ) ?mclr pin (see section 2.3 ?master clear (mclr) pin? ) these pins must also be connected if they are being used in the end application: ? pgc/pgd pins used for in-circuit serial programming? (icsp?) and debugging purposes (see section 2.5 ?icsp pins? ) ? osci and osco pins when an external oscillator source is used (see section 2.6 ?external oscillator pins? ) additionally, the following pins may be required: ?v ref +/v ref - pins are used when external voltage reference for analog modules is implemented the minimum mandatory connections are shown in figure 2-1 . figure 2-1: recommended minimum connections note: the av dd and av ss pins must always be connected, regardless of whether any of the analog modules are being used. pic18fxxkxx v dd v ss v dd v ss v ss v dd av dd av ss v dd v ss c1 r1 v dd mclr v cap /v ddcore r2 c7 (1) c2 (1) c3 (1) c4 (1) c5 (1) c6 (1) key (all values are recommendations): c1 through c6: 0.1 ? f, 20v ceramic r1: 10 k ? r2: 100 ? to 470 ? note 1: the example shown is for a pic18f device with five v dd /v ss and av dd /av ss pairs. other devices may have more or less pairs; adjust the number of decoupling capacitors appropriately.
pic18f66k80 family ds39977d-page 48 ? 2011 microchip technology inc. 2.2 power supply pins 2.2.1 decoupling capacitors the use of decoupling capacitors on every pair of power supply pins, such as v dd , v ss , av dd and av ss , is required. consider the following criteria when using decoupling capacitors: ? value and type of capacitor: a 0.1 ? f (100 nf), 10-20v capacitor is recommended. the capacitor should be a low-esr device, with a resonance frequency in the range of 200 mhz and higher. ceramic capacitors are recommended. ? placement on the printed circuit board: the decoupling capacitors should be placed as close to the pins as possible. it is recommended to place the capacitors on the same side of the board as the device. if space is constricted, the capacitor can be placed on another layer on the pcb using a via; however, ensure that the trace length from the pin to the capacitor is no greater than 0.25 inch (6 mm). ? handling high-frequency noise: if the board is experiencing high-frequency noise (upward of tens of mhz), add a second ceramic type capaci- tor in parallel to the above described decoupling capacitor. the value of the second capacitor can be in the range of 0.01 ? f to 0.001 ? f. place this second capacitor next to each primary decoupling capacitor. in high-speed circuit designs, consider implementing a decade pair of capacitances as close to the power and ground pins as possible (e.g., 0.1 ? f in parallel with 0.001 ? f). ? maximizing performance: on the board layout from the power supply circuit, run the power and return traces to the decoupling capacitors first, and then to the device pins. this ensures that the decoupling capacitors are first in the power chain. equally important is to keep the trace length between the capacitor and the power pins to a minimum, thereby reducing pcb trace inductance. 2.2.2 tank capacitors on boards with power traces running longer than six inches in length, it is suggested to use a tank capac- itor for integrated circuits, including microcontrollers, to supply a local power source. the value of the tank capacitor should be determined based on the trace resistance that connects the power supply source to the device, and the maximum current drawn by the device in the application. in other words, select the tank capacitor so that it meets the acceptable voltage sag at the device. typical values range from 4.7 ? f to 47 ? f. 2.3 master clear (mclr ) pin the mclr pin provides two specific device functions: device reset, and device programming and debugging. if programming and debugging are not required in the end application, a direct connection to v dd may be all that is required. the addition of other components, to help increase the application?s resistance to spurious resets from voltage sags, may be beneficial. a typical configuration is shown in figure 2-1 . other circuit designs may be implemented, depending on the application?s requirements. during programming and debugging, the resistance and capacitance that can be added to the pin must be considered. device programmers and debuggers drive the mclr pin. consequently, specific voltage levels (v ih and v il ) and fast signal transitions must not be adversely affected. therefore, specific values of r1 and c1 will need to be adjusted based on the application and pcb requirements. for example, it is recommended that the capacitor, c1, be isolated from the mclr pin during programming and debugging operations by using a jumper ( figure 2-2 ). the jumper is replaced for normal run-time operations. any components associated with the mclr pin should be placed within 0.25 inch (6 mm) of the pin. figure 2-2: example of mclr pin connections note 1: r1 ?? 10 k ? is recommended. a suggested starting value is 10 k ? . ensure that the mclr pin v ih and v il specifications are met. 2: r2 ?? 470 ? will limit any current flowing into mclr from the external capacitor, c, in the event of mclr pin breakdown, due to electrostatic discharge (esd) or electrical overstress (eos). ensure that the mclr pin v ih and v il specifications are met. c1 r2 r1 v dd mclr pic18fxxkxx jp
? 2011 microchip technology inc. ds39977d-page 49 pic18f66k80 family 2.4 voltage regulator pins (v cap /v ddcore ) on the pic18f66k80 family devices, the regulator is enabled and a low-esr (< 5 ? ) capacitor is required on the v cap /v ddcore pin to stabilize the voltage regulator output voltage. the v cap /v ddcore pin must not be connected to v dd and must use a capacitor of 10 f connected to ground. the type can be ceramic or tantalum. suitable examples of capacitors are shown in table 2-1 . capacitors with equivalent specifications can be used. designers may use figure 2-3 to evaluate esr equivalence of candidate devices. it is recommended that the trace length not exceed 0.25 inch (6 mm). refer to section 31.0 ?electrical characteristics? for additional information. when the regulator is disabled, a 0.1 ? f capacitor should be connected from the v cap /v ddcore pin to ground. this capacitor?s characteristics must be similar to those of the ?decoupling? capacitors explained in section 2.2.1 . for details on the v dd requirement, when the regulator is disabled, see parameter d001 in section 31.0 ?electrical characteristics? . some pic18fxxkxx families or some devices within a family do not provide the option of enabling or disabling the on-chip voltage regulator: ?the pic18 lf xxkxx devices permanently disable the voltage regulator. these devices require a 0.1 ? f capacitor on the v cap /v ddcore pin. the v dd level of these devices must comply with the ?voltage regulator disabled? specification for parameter d001, in section 31.0 ?electrical characteristics? . ? pic18fxxkxx devices permanently enable the voltage regulator. these devices require a 10 ? f capacitor on the v cap /v ddcore pin. for details on all members of the pic18f66k80 family, see section 28.3 ?on-chip voltage regulator? . figure 2-3: frequency vs. esr performance for suggested v cap 2.5 icsp pins the pgc and pgd pins are used for in-circuit serial programming? (icsp?) and debugging purposes. it is recommended to keep the trace length between the icsp connector and the icsp pins on the device as short as possible. if the icsp connector is expected to experience an esd event, a series resistor is recom- mended, with the value in the range of a few tens of ohms, not to exceed 100 ? . pull-up resistors, series diodes, and capacitors on the pgc and pgd pins are not recommended as they will interfere with the programmer/debugger communica- tions to the device. if such discrete components are an application requirement, they should be removed from the circuit during programming and debugging. alter- natively, refer to the ac/dc characteristics and timing requirements information in the respective device flash programming specification for information on capacitive loading limits, and pin input voltage high (v ih ) and input low (v il ) requirements. for device emulation, ensure that the ?communication channel select? (i.e., pgcx/pgdx pins) programmed into the device matches the physical connections for the icsp to the microchip debugger/emulator tool. for more information on available microchip development tools connection requirements, refer to section 30.0 ?development support? . 10 1 0.1 0.01 0.001 0.01 0.1 1 10 100 1000 10,000 frequency (mhz) esr ( ? ) note: typical data measurement at 25c, 0v dc bias.
pic18f66k80 family ds39977d-page 50 ? 2011 microchip technology inc. 2.6 external oscillator pins many microcontrollers have options for at least two oscillators: a high-frequency primary oscillator and a low-frequency secondary oscillator (refer to section 3.0 ?oscillator configurations? for details). the oscillator circuit should be placed on the same side of the board as the device. place the oscillator circuit close to the respective oscillator pins with no more than 0.5 inch (12 mm) between the circuit components and the pins. the load capacitors should be placed next to the oscillator itself, on the same side of the board. use a grounded copper pour around the oscillator cir- cuit to isolate it from surrounding circuits. the grounded copper pour should be routed directly to the mcu ground. do not run any signal traces or power traces inside the ground pour. also, if using a two-sided board, avoid any traces on the other side of the board where the crystal is placed. layout suggestions are shown in figure 2-4. in-line packages may be handled with a single-sided layout that completely encompasses the oscillator pins. with fine-pitch packages, it is not always possible to com- pletely surround the pins and components. a suitable solution is to tie the broken guard sections to a mirrored ground layer. in all cases, the guard trace(s) must be returned to ground. table 2-1 suitable capacitor equivalents make part # nominal capacitance base tolerance rated voltage temp. range tdk c3216x7r1c106k 10 f 10% 16v -55 to 125oc tdk c3216x5r1c106k 10 f 10% 16v -55 to 85oc panasonic ecj-3yx1c106k 10 f 10% 16v -55 to 125oc panasonic ecj-4yb1c106k 10 f 10% 16v -55 to 85oc murata grm32dr71c106ka01l 10 f 10% 16v -55 to 125oc murata grm31cr61c106kc31l 10 f 10% 16v -55 to 85oc
? 2011 microchip technology inc. ds39977d-page 51 pic18f66k80 family in planning the application?s routing and i/o assign- ments, ensure that adjacent port pins and other signals in close proximity to the oscillator are benign (i.e., free of high frequencies, short rise and fall times, and other similar noise). for additional information and design guidance on oscillator circuits, please refer to these microchip application notes, available at the corporate web site (www.microchip.com): ? an826, ? crystal oscillator basics and crystal selection for rfpic? and picmicro ? devices? ? an849, ?basic picmicro ? oscillator design? ? an943, ?practical picmicro ? oscillator analysis and design? ? an949, ?making your oscillator work? 2.7 unused i/os unused i/o pins should be configured as outputs and driven to a logic low state. alternatively, connect a 1 k ? to 10 k ? resistor to v ss on unused pins and drive the output to logic low. figure 2-4: suggested placement of the oscillator circuit gnd ` ` ` osc1 osc2 t1oso t1os i copper pour primary oscillator crystal timer1 oscillator crystal device pins primary oscillator c1 c2 t1 oscillator: c1 t1 oscillator: c2 (tied to ground) single-sided and in-line layouts: fine-pitch (dual-sided) layouts: gnd osco osci bottom layer copper pour oscillator crystal top layer copper pour c2 c1 device pins (tied to ground) (tied to ground)
pic18f66k80 family ds39977d-page 52 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds39977d-page 53 pic18f66k80 family 3.0 oscillator configurations 3.1 oscillator types the pic18f66k80 family of devices can be operated in the following oscillator modes: ? ec external clock, ra6 available ? ecio external clock, clock out ra6 (f osc /4 on ra6) ? hs high-speed crystal/resonator ? xt crystal/resonator ? lp low-power crystal ? rc external resistor/capacitor, ra6 available ? rcio external resistor/capacitor, clock out ra6 (f osc /4 on ra6) ? intio2 internal oscillator with i/o on ra6 and ra7 ? intio1 internal oscillator with f osc /4 output on ra6 and i/o on ra7 there is also an option for running the 4xpll on any of the clock sources in the input frequency range of 4 to 16 mhz. the pll is enabled by setting the pllcfg bit (config1h<4>) or the pllen bit (osctune<6>). for the ec and hs modes, the pllen (software) or pllcfg (config1h<4>) bit can be used to enable the pll. for the intiox modes (hf-intosc): ? only the pllen can enable the pll (pllcfg is ignored). ? when the oscillator is configured for the internal oscillator (fosc<3:0> = 100x ), the pll can be enabled only when the hf-intosc frequency is 4, 8 or 16 mhz. when the ra6 and ra7 pins are not used for an oscil- lator function or clkout function, they are available as general purpose i/os. to optimize power consumption when using ec/hs/ xt/lp/rc as the primary oscillator, the frequency input range can be configured to yield an optimized power bias: ? low-power bias ? external frequency less than 160 khz ? medium power bias ? external frequency between 160 khz and 16 mhz ? high-power bias ? external frequency greater than 16 mhz all of these modes are selected by the user by programming the fosc<3:0> configuration bits (config1h<3:0>). in addition, pic18f66k80 family devices can switch between different clock sources, either under software control, or under certain condi- tions, automatically. this allows for additional power savings by managing device clock speed in real time without resetting the application. the clock sources for the pic18f66k80 family of devices are shown in figure 3-1 . for the hs and ec mode, there are additional power modes of operation, depending on the frequency of operation. hs1 is the medium power mode with a frequency range of 4 mhz to 16 mhz. hs2 is the high-power mode, where the oscillator frequency can go from 16 mhz to 25 mhz. hs1 and hs2 are achieved by setting the config1h<3:0> bits correctly. (for details, see register 28-2 on page 462.) ec mode has these modes of operation: ? ec1 ? for low power with a frequency range up to 160 khz ? ec2 ? medium power with a frequency range of 160 khz to 16 mhz ? ec3 ? high power with a frequency range of 16 mhz to 64 mhz ec1, ec2 and ec3 are achieved by setting the config1h<3:0> correctly. (for details, see register 28-2 on page 462.) table 3-1 shows the hs and ec modes? frequency range and fosc<3:0> settings.
pic18f66k80 family ds39977d-page 54 ? 2011 microchip technology inc. figure 3-1: pic18f66k80 family clock diagram table 3-1: hs, ec, xt, lp and rc modes: ranges and settings mode frequency range fosc<3:0> setting ec1 (low power) dc-160 khz 1101 (ec1 & ec1io) 1100 ec2 (medium power) 160khz-16mhz 1011 (ec2 & ec2io) 1010 ec3 (high power) 16 mhz-64 mhz 0101 (ec3 & ec3io) 0100 hs1 (medium power) 4 mhz-16 mhz 0011 hs2 (high power) 16 mhz-25 mhz 0010 xt 100 khz-4 mhz 0001 lp 31.25 khz 0000 rc (external) 0-4 mhz 001x intio 32khz-16mhz 100x (and osccon, osccon2) osc2 osc1 sosco sosci hf-intosc 16 mhz to 31 khz mf-intosc 500 khz to 31 khz lf-intosc 31 khz postscaler postscaler 16 mhz 8 mhz 4 mhz 2 mhz 1 mhz 500 khz 250 khz 31 khz 500 khz 250 khz 31 khz 31 khz 16 mhz 8 mhz 4 mhz 2 mhz 1 mhz 500 khz 250 khz 31 khz 4x pll fosc<3:0> intsrc mux mux mux mux mfiosel mux peripherals cpu idlen clock control fosc<3:0> scs<1:0> 111 110 101 100 011 010 001 000 ircf<2:0> mux pllen and pllcfg
? 2011 microchip technology inc. ds39977d-page 55 pic18f66k80 family 3.2 control registers the osccon register ( register 3-1 ) controls the main aspects of the device clock?s operation. it selects the oscillator type to be used, which of the power-managed modes to invoke and the output frequency of the intosc source. it also provides status on the oscillators. the osctune register ( register 3-3 ) controls the tuning and operation of the internal oscillator block. it also implements the pllen bit which controls the operation of the phase locked loop (pll) (see section 3.5.3 ?pll frequency multiplier? ). register 3-1: osccon: os cillator control register r/w-0 r/w-1 r/w-0 r/w-0 r (1) r-0 r/w-0 r/w-0 idlen ircf2 (2) ircf1 (2) ircf0 (2) osts hfiofs scs1 (4) scs0 (4) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 idlen: idle enable bit 1 = device enters an idle mode when a sleep instruction is executed 0 = device enters sleep mode when a sleep instruction is executed bit 6-4 ircf<2:0>: internal oscillator frequency select bits (2) 111 = hf-intosc output frequency is used (16 mhz) 110 = hf-intosc/2 output frequency is used (8 mhz, default) 101 = hf-intosc/4 output frequency is used (4 mhz) 100 = hf-intosc/8 output frequency is used (2 mhz) 011 = hf-intosc/16 output frequency is used (1 mhz) if intsrc = 0 and mfiosel = 0 : (3,5) 010 = hf-intosc/32 output frequency is used (500 khz) 001 = hf-intosc/64 output frequency is used (250 khz) 000 = lf-intosc output frequency is used (31.25 khz) (6) if intsrc = 1 and mfiosel = 0 : (3,5) 010 = hf-intosc/32 output frequency is used (500 khz) 001 = hf-intosc/64 output frequency is used (250 khz) 000 = hf-intosc/512 output frequency is used (31.25 khz) if intsrc = 0 and mfiosel = 1 : (3,5) 010 = mf-intosc output frequency is used (500 khz) 001 = mf-intosc/2 output frequency is used (250 khz) 000 = lf-intosc output frequency is used (31.25 khz) (6) if intsrc = 1 and mfiosel = 1 : (3,5) 010 = mf-intosc output frequency is used (500 khz) 001 = mf-intosc/2 output frequency is used (250 khz) 000 = mf-intosc/16 output frequency is used (31.25 khz) bit 3 osts: oscillator start-up timer time-out status bit (1) 1 = oscillator start-up timer (ost) time-out has expired; primary oscillator is running, as defined by fosc<3:0> 0 = oscillator start-up timer (ost) time-out is running; primary oscillator is not ready ? device is running from internal oscillator (hf-intosc, mf-intosc or lf-intosc) note 1: reset state depends on the state of the ieso configuration bit (config1h<7>). 2: modifying these bits will cause an immediate clock frequency switch if the internal oscillator is providing the device clocks. 3: source selected by the intsrc bit (osctune<7>). 4: modifying these bits will cause an immediate clock source switch. 5: intsrc = osctune<7> and mfiosel = osccon2<0>. 6: lowest power option for an internal source.
pic18f66k80 family ds39977d-page 56 ? 2011 microchip technology inc. bit 2 hfiofs: hf-intosc frequency stable bit 1 = hf-intosc oscillator frequency is stable 0 = hf-intosc oscillator frequency is not stable bit 1-0 scs<1:0>: system clock select bits (4) 1x = internal oscillator block (lf-intosc, mf-intosc or hf-intosc) 01 = sosc oscillator 00 = default primary oscillator (osc1/osc2 or hf-intosc with or without pll. defined by the fosc<3:0> configuration bits, config1h<3:0>.) register 3-1: osccon: oscillato r control register (continued) note 1: reset state depends on the state of the ieso configuration bit (config1h<7>). 2: modifying these bits will cause an immediate clock frequency switch if the internal oscillator is providing the device clocks. 3: source selected by the intsrc bit (osctune<7>). 4: modifying these bits will cause an immediate clock source switch. 5: intsrc = osctune<7> and mfiosel = osccon2<0>. 6: lowest power option for an internal source. register 3-2: osccon2: osci llator control register 2 u-0 r-0 u-0 r/w-0 r/w-0 u-0 r-x r/w-0 ? soscrun ?soscdrv (1) soscgo ? mfiofs mfiosel bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 soscrun: sosc run status bit 1 = system clock comes from a secondary sosc 0 = system clock comes from an oscillator other than sosc bit 5 unimplemented: read as ? 0 ? bit 4 soscdrv: secondary oscillator drive control bit (1) 1 = high-power sosc circuit is selected 0 = low/high-power select is done via the soscsel<1:0> configuration bits bit 3 soscgo: oscillator start control bit 1 = oscillator is running even if no other sources are requesting it. 0 = oscillator is shut off if no other sources are requesting it (when the sosc is selected to run from a digital clock input, rather than an external crystal, this bit has no effect.) bit 2 unimplemented: read as ? 0 ? bit 1 mfiofs: mf-intosc frequency stable bit 1 = mf-intosc is stable 0 = mf-intosc is not stable bit 0 mfiosel: mf-intosc select bit 1 = mf-intosc is used in place of hf-intosc frequencies of 500 khz, 250 khz and 31.25 khz 0 = mf-intosc is not used note 1: when sosc is selected to run from a digital clock input, rather than an external crystal, this bit has no effect.
? 2011 microchip technology inc. ds39977d-page 57 pic18f66k80 family register 3-3: osctune: osci llator tuning register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 intsrc pllen tun5 tun4 tun3 tun2 tun1 tun0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 intsrc: internal oscillator low-frequency source select bit 1 = 31.25 khz device clock derived from 16 mhz intosc source (divide-by-512 enabled, hf-intosc) 0 = 31 khz device clock derived from intosc 31 khz oscillator (lf-intosc) bit 6 pllen: frequency multiplier pll enable bit 1 = pll is enabled 0 = pll is disabled bit 5-0 tun<5:0>: fast rc oscillator (intosc) frequency tuning bits 011111 = maximum frequency ? ? ? ? 000001 000000 = center frequency; fast rc oscillator is running at the calibrated frequency 111111 ? ? ? ? 100000 = minimum frequency
pic18f66k80 family ds39977d-page 58 ? 2011 microchip technology inc. 3.3 clock sources and oscillator switching essentially, pic18f66k80 family devices have these independent clock sources: ? primary oscillators ? secondary oscillators ? internal oscillator the primary oscillators can be thought of as the main device oscillators. these are any external oscillators connected to the osc1 and osc2 pins, and include the external crystal and resonator modes and the external clock modes. if selected by the fosc<3:0> configuration bits (config1h<3:0>), the internal oscillator block may be considered a primary oscillator. the internal oscillator block can be one of the following: ? 31 khz lf-intosc source ? 31 khz to 500 khz mf-intosc source ? 31 khz to 16 mhz hf-intosc source the particular mode is defined by the fosc configuration bits. the details of these modes are covered in section 3.5 ?external oscillator modes? . the secondary oscillators are external clock sources that are not connected to the osc1 or osc2 pin. these sources may continue to operate, even after the controller is placed in a power-managed mode. pic18f66k80 family devices offer the sosc (timer1/3/5/7) oscillator as a secondary oscillator source. the sosc can be enabled from any peripheral that requests it. the sosc can be enabled several ways by doing one of the following: ? the sosc is selected as the source by either of the odd timers, which is done by each respective soscen bit (txcon<3>) ? the sosc is selected as the cpu clock source by the scs bits (osccon<1:0>) ? the soscgo bit is set (osccon2<3>) the soscgo bit is used to warm up the sosc so that it is ready before any peripheral requests it. the secondary oscillator has three run modes. the soscsel<1:0> bits (config1l<4:3>) decide the sosc mode of operation: ? 11 = high-power sosc circuit ? 10 = digital (sclki) mode ? 11 = low-power sosc circuit if a secondary oscillator is not desired and digital i/o on port pins, rc0 and rc1, is needed, the soscsel bits must be set to digital mode. in addition to being a primary clock source in some circumstances, the internal oscillator is available as a power-managed mode clock source. the lf-intosc source is also used as the clock source for several special features, such as the wdt and fail-safe clock monitor. the internal oscillator block is discussed in more detail in section 3.6 ?internal oscillator block? . the pic18f66k80 family includes features that allow the device clock source to be switched from the main oscillator, chosen by device configuration, to one of the alternate clock sources. when an alternate clock source is enabled, various power-managed operating modes are available. 3.3.1 osc1/osc2 oscillator the osc1/osc2 oscillator block is used to provide the oscillator modes and frequency ranges: the crystal-based oscillators (xt, hs and lp) have a built-in start-up time. the operation of the ec and extrc clocks is immediate. 3.3.2 clock source selection the system clock select bits, scs<1:0> (osccon<1:0>), select the clock source. the avail- able clock sources are the primary clock defined by the fosc<3:0> configuration bits, the secondary clock (sosc oscillator) and the internal oscillator. the clock source changes after one or more of the bits is written to, following a brief clock transition interval. the osts (osccon<3>) and soscrun (osccon2<6>) bits indicate which clock source is currently providing the device clock. the osts bit indicates that the oscillator start-up timer (ost) has timed out and the primary clock is providing the device clock in primary clock modes. the soscrun bit indi- cates when the sosc oscillator (from timer1/3/5/7) is providing the device clock in secondary clock modes. in power-managed modes, only one of these bits will be set at any time. if neither of these bits is set, the intosc is providing the clock or the internal oscillator has just started and is not yet stable. the idlen bit (osccon<7>) determines if the device goes into sleep mode or one of the idle modes when the sleep instruction is executed. mode design operating frequency lp 31.25-100 khz xt 100 khz to 4 mhz hs 4 mhz to 25 mhz ec 0 to 64 mhz (external clock) extrc 0 to 4 mhz (external rc)
? 2011 microchip technology inc. ds39977d-page 59 pic18f66k80 family the use of the flag and control bits in the osccon register is discussed in more detail in section 4.0 ?power-managed modes? . 3.3.2.1 system clock selection and device resets since the scs bits are cleared on all forms of reset, this means the primary oscillator defined by the fosc<3:0> configuration bits is used as the primary clock source on device resets. this could either be the internal oscillator block by itself, or one of the other primary clock sources (hs, ec, xt, lp, external rc and pll-enabled modes). in those cases when the internal oscillator block, with- out pll, is the default clock on reset, the fast rc oscillator (intosc) will be used as the device clock source. it will initially start at 8 mhz; the postscaler selection that corresponds to the reset value of the ircf<2:0> bits (? 110 ?). regardless of which primary oscillator is selected, intosc will always be enabled on device power-up. it serves as the clock source until the device has loaded its configuration values from memory. it is at this point that the fosc configuration bits are read and the oscillator selection of the operational mode is made. note that either the primary clock source or the internal oscillator will have two bit setting options for the possible values of the scs<1:0> bits, at any given time. 3.3.3 oscillator transitions pic18f66k80 family devices contain circuitry to prevent clock ?glitches? when switching between clock sources. a short pause in the device clock occurs during the clock switch. the length of this pause is the sum of two cycles of the old clock source and three to four cycles of the new clock source. this formula assumes that the new clock source is stable. clock transitions are discussed in greater detail in section 4.1.2 ?entering power-managed modes? . 3.4 rc oscillator for timing-insensitive applications, the rc and rcio oscillator modes offer additional cost savings. the actual oscillator frequency is a function of several factors: ? supply voltage ? values of the external resistor (r ext ) and capacitor (c ext ) ? operating temperature given the same device, operating voltage and temper- ature, and component values, there will also be unit to unit frequency variations. these are due to factors such as: ? normal manufacturing variation ? difference in lead frame capacitance between package types (especially for low c ext values) ? variations within the tolerance of the limits of r ext and c ext in the rc oscillator mode, the oscillator frequency, divided by 4, is available on the osc2 pin. this signal may be used for test purposes or to synchronize other logic. figure 3-2 shows how the r/c combination is connected. figure 3-2: rc oscillator mode the rcio oscillator mode ( figure 3-3 ) functions like the rc mode, except that the osc2 pin becomes an additional general purpose i/o pin. the i/o pin becomes bit 6 of porta (ra6). figure 3-3: rcio oscillator mode note 1: the timer1/3/5/7 oscillator must be enabled to select the secondary clock source. the timerx oscillator is enabled by setting the soscen bit in the timerx control register (txcon<3>). if the tim- erx oscillator is not enabled, then any attempt to select a secondary clock source when executing a sleep instruc- tion will be ignored. 2: it is recommended that the timerx oscillator be operating and stable before executing the sleep instruction or a very long delay may occur while the timerx oscillator starts. osc2/clko c ext r ext pic18f66k80 osc1 f osc /4 internal clock v dd v ss recommended values: 3 k ? ? r ext ? 100 k ? 20 pf ?? c ext ? 300 pf c ext r ext pic18f66k80 osc1 internal clock v dd v ss recommended values: 3 k ? ? r ext ? 100 k ? 20 pf ?? c ext ? 300 pf i/o (osc2) ra6
pic18f66k80 family ds39977d-page 60 ? 2011 microchip technology inc. 3.5 external oscillator modes 3.5.1 crystal oscillator/ceramic resonators (hs modes) in hs or hspll oscillator modes, a crystal or ceramic resonator is connected to the osc1 and osc2 pins to establish oscillation. figure 3-4 shows the pin connections. the oscillator design requires the use of a crystal rated for parallel resonant operation. table 3-2: capacitor selection for ceramic resonators table 3-3: capacitor selection for crystal oscillator figure 3-4: crystal/ceramic resonator operation (hs or hspll configuration) note: use of a crystal rated for series resonant operation may give a frequency out of the crystal manufacturer?s specifications. typical capacitor values used: mode freq. osc1 osc2 hs 8.0 mhz 16.0 mhz 27 pf 22 pf 27 pf 22 pf capacitor values are for design guidance only. different capacitor values may be required to produce acceptable oscillator operation. the user should test the performance of the oscillator over the expected v dd and temperature range for the application. refer to the following application notes for oscillator-specific information: ? an588, ?pic ? microcontroller oscillator design guide? ? an826, ?crystal oscillator basics and crystal selection for rfpic ? and pic ? devices? ? an849, ?basic pic ? oscillator design? ? an943, ?practical pic ? oscillator analysis and design? ? an949, ?making your oscillator work? see the notes following tab l e 3 - 3 for additional information. osc type crystal freq. typical capacitor values tested: c1 c2 hs 4 mhz 27 pf 27 pf 8 mhz 22 pf 22 pf 20 mhz 15 pf 15 pf capacitor values are for design guidance only. different capacitor values may be required to produce acceptable oscillator operation. the user should test the performance of the oscillator over the expected v dd and temperature range for the application. refer to the microchip application notes cited in table 3-2 for oscillator specific information. also see the notes following this table for additional information. note 1: higher capacitance increases the stability of oscillator but also increases the start-up time. 2: since each resonator/crystal has its own characteristics, the user should consult the resonator/crystal manufacturer for appropriate values of external components. 3: rs may be required to avoid overdriving crystals with low drive level specification. 4: always verify oscillator performance over the v dd and temperature range that is expected for the application. note 1: see ta b l e 3 - 2 and table 3-3 for initial values of c1 and c2. 2: a series resistor (r s ) may be required for at strip cut crystals. 3: r f varies with the oscillator mode chosen. c1 (1) c2 (1) xtal osc2 osc1 r f (3) sleep to logic r s (2) internal pic18f66k80
? 2011 microchip technology inc. ds39977d-page 61 pic18f66k80 family 3.5.2 external clock input (ec modes) the ec and ecpll oscillator modes require an external clock source to be connected to the osc1 pin. there is no oscillator start-up time required after a power-on reset or after an exit from sleep mode. in the ec oscillator mode, the oscillator frequency divided by 4 is available on the osc2 pin. this signal may be used for test purposes or to synchronize other logic. figure 3-5 shows the pin connections for the ec oscillator mode. figure 3-5: external clock input operation (ec configuration) an external clock source may also be connected to the osc1 pin in the hs mode, as shown in figure 3-6 . in this configuration, the divide-by-4 output on osc2 is not available. current consumption in this configuration will be somewhat higher than ec mode, as the internal oscillator?s feedback circuitry will be enabled (in ec mode, the feedback circuit is disabled). figure 3-6: external clock input operation (hs osc configuration) 3.5.3 pll frequency multiplier a phase lock loop (pll) circuit is provided as an option for users who want to use a lower frequency oscillator circuit or to clock the device up to its highest rated frequency from a crystal oscillator. this may be useful for customers who are concerned with emi due to high-frequency crystals or users who require higher clock speeds from an internal oscillator. 3.5.3.1 hspll and ecpll modes the hspll and ecpll modes provide the ability to selectively run the device at four times the external oscillating source to produce frequencies up to 64 mhz. the pll is enabled by setting the pllen bit (osctune<6>) or the pllcfg bit (config1h<4>). for the hf-intosc as primary, the pll must be enabled with the pllen. this provides a software con- trol for the pll, enabling even if pllcfg is set to ? 1 ?, so that the pll is enabled only when the hf-intosc frequency is within the 4 mhz to16 mhz input range. this also enables additional flexibility for controlling the application?s clock speed in software. the pllen should be enabled in hf-intosc mode only if the input frequency is in the range of 4 mhz-16 mhz. figure 3-7: pll block diagram 3.5.3.2 pll and hf-intosc the pll is available to the internal oscillator block when the internal oscillator block is configured as the primary clock source. in this configuration, the pll is enabled in software and generates a clock output of up to 64 mhz. the operation of intosc with the pll is described in section 3.6.2 ?intpll modes? . care should be taken that the pll is enabled only if the hf-intosc postscaler is configured for 4 mhz, 8 mhz or 16 mhz . osc1/clki osc2/clko f osc /4 clock from ext. system pic18f66k80 osc1 osc2 open clock from ext. system (hs mode) pic18f66k80 mux vco loop filter osc2 osc1 pll enable (osctune<6>) f in f out sysclk phase comparator pllcfg (config1h<4>) ? 4 hs or ec mode
pic18f66k80 family ds39977d-page 62 ? 2011 microchip technology inc. 3.6 internal oscillator block the pic18f66k80 family of devices includes an internal oscillator block which generates two different clock signals. either clock can be used as the microcontroller?s clock source, which may eliminate the need for an external oscillator circuit on the osc1 and/or osc2 pins. the internal oscillator consists of three blocks, depending on the frequency of operation. they are hf-intosc, mf-intosc and lf-intosc. in hf-intosc mode, the internal oscillator can provide a frequency ranging from 31 khz to 16 mhz, with the postscaler deciding the selected frequency (ircf<2:0>). the intsrc bit (osctune<7>) and mfiosel bit (osccon2<0>) also decide which intosc provides the lower frequency (500 khz to 31 khz). for the hf-intosc to provide these frequencies, intsrc = 1 and mfiosel = 0 . in hf-intosc, the postscaler (ircf<2:0>) provides the frequency range of 31 khz to 16 mhz. if hf-intosc is used with the pll, the input frequency to the pll should be 4 mhz to 16 mhz (ircf<2:0> = 111 , 110 or 101 ). for mf-intosc mode to provide a frequency range of 500 khz to 31 khz, intsrc = 1 and mfiosel = 1 . the postscaler (ircf<2:0>), in this mode, provides the frequency range of 31 khz to 500 khz. the lf-intosc can provide only 31 khz if intsrc = 0 . the lf-intosc provides 31 khz and is enabled if it is selected as the device clock source. the mode is enabled automatically when any of the following are enabled: ? power-up timer ? fail-safe clock monitor ? watchdog timer ? two-speed start-up these features are discussed in greater detail in section 28.0 ?special features of the cpu? . the clock source frequency (hf-intosc, mf-intosc or lf-intosc direct) is selected by configuring the ircf bits of the osccon register, as well the intsrc and mfiosel bits. the default frequency on device resets is 8 mhz. 3.6.1 intio modes using the internal oscillator as the clock source elimi- nates the need for up to two external oscillator pins, which can then be used for digital i/o. two distinct oscillator configurations, which are determined by the fosc configuration bits, are available: ? in intio1 mode, the osc2 pin (ra6) outputs f osc /4, while osc1 functions as ra7 (see figure 3-8 ) for digital input and output. ? in intio2 mode, osc1 functions as ra7 and osc2 functions as ra6 (see figure 3-9 ). both are available as digital input and output ports. figure 3-8: intio1 oscillator mode figure 3-9: intio2 oscillator mode 3.6.2 intpll modes the 4x phase lock loop (pll) can be used with the hf-intosc to produce faster device clock speeds than are normally possible with the internal oscillator sources. when enabled, the pll produces a clock speed of 16 mhz or 64 mhz. pll operation is controlled through software. the control bits, pllen (osctune<6>) and pllcfg (config1h<4>), are used to enable or disable its operation. the pll is available only to hf-intosc. the other oscillator is set with hs and ec modes. addi- tionally, the pll will only function when the selected output frequency is either 4 mhz or 16 mhz (osccon<6:4> = 111 , 110 or 101 ). like the intio modes, there are two distinct intpll modes available: ? in intpll1 mode, the osc2 pin outputs f osc /4, while osc1 functions as ra7 for digital input and output. externally, this is identical in appearance to intio1 ( figure 3-8 ). ? in intpll2 mode, osc1 functions as ra7 and osc2 functions as ra6, both for digital input and output. externally, this is identical to intio2 ( figure 3-9 ). osc2 f osc /4 i/o (osc1) ra7 pic18f66k80 i/o (osc2) ra6 i/o (osc1) ra7 pic18f66k80
? 2011 microchip technology inc. ds39977d-page 63 pic18f66k80 family 3.6.3 internal oscillator output frequency and tuning the internal oscillator block is calibrated at the factory to produce an intosc output frequency of 16 mhz. it can be adjusted in the user?s application by writing to tun<5:0> (osctune<5:0>) in the osctune register ( register 3-3 ). when the osctune register is modified, the intosc (hf-intosc and mf-intosc) frequency will begin shifting to the new frequency. the oscillator will require some time to stabilize. code execution continues during this shift and there is no indication that the shift has occurred. the lf-intosc oscillator operates independently of the hf-intosc or the mf-intosc source. any changes in the hf-intosc or the mf-intosc source, across voltage and temperature, are not necessarily reflected by changes in lf-intosc or vice versa. the frequency of lf-intosc is not affected by osctune. 3.6.4 intosc frequency drift the intosc frequency may drift as v dd or tempera- ture changes and can affect the controller operation in a variety of ways. it is possible to adjust the intosc frequency by modifying the value in the osctune register. depending on the device, this may have no effect on the lf-intosc clock source frequency. tuning intosc requires knowing when to make the adjustment, in which direction it should be made, and in some cases, how large a change is needed. three compensation techniques are shown here. 3.6.4.1 compensating with the eusart an adjustment may be required when the eusart begins to generate framing errors or receives data with errors while in asynchronous mode. framing errors indicate that the device clock frequency is too high. to adjust for this, decrement the value in osctune to reduce the clock frequency. on the other hand, errors in data may suggest that the clock speed is too low. to compensate, increment osctune to increase the clock frequency. 3.6.4.2 compensating with the timers this technique compares device clock speed to some reference clock. two timers may be used; one timer is clocked by the peripheral clock, while the other is clocked by a fixed reference source, such as the sosc oscillator. both timers are cleared, but the timer clocked by the reference generates interrupts. when an interrupt occurs, the internally clocked timer is read and both timers are cleared. if the internally clocked timer value is much greater than expected, then the internal oscillator block is running too fast. to adjust for this, decrement the osctune register. 3.6.4.3 compensating with the ccp module in capture mode a ccp module can use free-running timer1 (or timer3), clocked by the internal oscillator block and an external event with a known period (i.e., ac power frequency). the time of the first event is captured in the ccprxh:ccprxl registers and is recorded for use later. when the second event causes a capture, the time of the first event is subtracted from the time of the second event. since the period of the external event is known, the time difference between events can be calculated. if the measured time is much greater than the calculated time, the internal oscillator block is running too fast. to compensate, decrement the osctune register. if the measured time is much less than the calculated time, the internal oscillator block is running too slow. to compensate, increment the osctune register. 3.7 reference clock output in addition to the f osc /4 clock output, in certain oscillator modes, the device clock in the pic18f66k80 family can also be configured to provide a reference clock output signal to a port pin. this feature is avail- able in all oscillator configurations and allows the user to select a greater range of clock submultiples to drive external devices in the application. this reference clock output is controlled by the refocon register ( register 3-4 ). setting the roon bit (refocon<7>) makes the clock signal available on the refo (rc3) pin. the rodiv<3:0> bits enable the selection of 16 different clock divider options. the rosslp and rosel bits (refocon<5:4>) con- trol the availability of the reference output during sleep mode. the rosel bit determines if the oscillator on osc1 and osc2, or the current system clock source, is used for the reference clock output. the rosslp bit determines if the reference source is available on re3 when the device is in sleep mode. to use the reference clock output in sleep mode, both the rosslp and rosel bits must be set. the device clock must also be configured for an ec or hs mode. if not, the oscillator on osc1 and osc2 will be powered down when the device enters sleep mode. clearing the rosel bit allows the reference output frequency to change as the system clock changes during any clock switches.
pic18f66k80 family ds39977d-page 64 ? 2011 microchip technology inc. register 3-4: refocon: reference oscillator control register r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 roon ? rosslp rosel (1) rodiv3 rodiv2 rodiv1 rodiv0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 roon: reference oscillator output enable bit 1 = reference oscillator output available on refo pin 0 = reference oscillator output disabled bit 6 unimplemented: read as ? 0 ? bit 5 rosslp: reference oscillator output stop in sleep bit 1 = reference oscillator continues to run in sleep 0 = reference oscillator is disabled in sleep bit 4 rosel: reference oscillator source select bit (1) 1 = primary oscillator (ec or hs) used as the base clock 0 = system clock used as the base clock; base clock reflects any clock switching of the device bit 3-0 rodiv<3:0>: reference oscillator divisor select bits 1111 = base clock value divided by 32,768 1110 = base clock value divided by 16,384 1101 = base clock value divided by 8,192 1100 = base clock value divided by 4,096 1011 = base clock value divided by 2,048 1010 = base clock value divided by 1,024 1001 = base clock value divided by 512 1000 = base clock value divided by 256 0111 = base clock value divided by 128 0110 = base clock value divided by 64 0101 = base clock value divided by 32 0100 = base clock value divided by 16 0011 = base clock value divided by 8 0010 = base clock value divided by 4 0001 = base clock value divided by 2 0000 = base clock value note 1: for rosel (refocon<4>), the primary oscillator is available only when configured as the default via the fosc settings. this is regardless of whether the device is in sleep mode.
? 2011 microchip technology inc. ds39977d-page 65 pic18f66k80 family 3.8 effects of power-managed modes on the various clock sources when pri_idle mode is selected, the designated pri- mary oscillator continues to run without interruption. for all other power-managed modes, the oscillator using the osc1 pin is disabled. the osc1 pin (and osc2 pin if used by the oscillator) will stop oscillating. in secondary clock modes (sec_run and sec_idle), the sosc oscillator is operating and providing the device clock. the sosc oscillator may also run in all power-managed modes if required to clock sosc. in rc_run and rc_idle modes, the internal oscillator provides the device clock source. the 31 khz lf-intosc output can be used directly to provide the clock and may be enabled to support various special features, regardless of the power-managed mode (see section 28.2 ?watchdog timer (wdt)? through section 28.5 ?fail-safe clock monitor? for more information on wdt, fail-safe clock monitor and two-speed start-up). if the sleep mode is selected, all clock sources are stopped. since all the transistor switching currents have been stopped, sleep mode achieves the lowest current consumption of the device (only leakage currents). enabling any on-chip feature that will operate during sleep will increase the current consumed during sleep. the intosc is required to support wdt operation. the sosc oscillator may be operating to support timer1 or 3. other features may be operating that do not require a device clock source (i.e., mssp slave, intx pins and others). peripherals that may add significant current consumption are listed in section 31.2 ?dc character- istics: power-down and supply current pic18f66k80 family (industrial/extended)? . 3.9 power-up delays power-up delays are controlled by two timers, so that no external reset circuitry is required for most applica- tions. the delays ensure that the device is kept in reset until the device power supply is stable under nor- mal circumstances and the primary clock is operating and stable. for additional information on power-up delays, see section 5.6.1 ?power-up timer (pwrt)? . the first timer is the power-up timer (pwrt), which provides a fixed delay on power-up time of about 64 ms (parameter 33, tab l e 3 1- 11 ); it is always enabled. the second timer is the oscillator start-up timer (ost), intended to keep the chip in reset until the crystal oscillator is stable (hs, xt or lp modes). the ost does this by counting 1,024 oscillator cycles before allowing the oscillator to clock the device. there is a delay of interval, t csd (parameter 38, table 31-11 ), following por, while the controller becomes ready to execute instructions. table 3-4: osc1 and osc2 pin states in sleep mode oscillator mode osc1 pin osc2 pin ec, ecpll floating, pulled by external clock at logic low (clock/4 output) hs, hspll feedback inverter disabled at quiescent voltage level feedback inverter disabled at quiescent voltage level intosc, intpll1/2 i/o pin, ra6, direction controlled by trisa<6> i/o pin, ra6, direction controlled by trisa<7> note: see section 5.0 ?reset? for time-outs due to sleep and mclr reset.
pic18f66k80 family ds39977d-page 66 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds39977d-page 67 pic18f66k80 family 4.0 power-managed modes the pic18f66k80 family of devices offers a total of seven operating modes for more efficient power man- agement. these modes provide a variety of options for selective power conservation in applications where resources may be limited (such as battery-powered devices). there are three categories of power-managed mode: ? run modes ? idle modes ? sleep mode there is an ultra low-power wake-up (ulpwu) for waking from sleep mode. these categories define which portions of the device are clocked, and sometimes, at what speed. the run and idle modes may use any of the three available clock sources (primary, secondary or internal oscillator block). the sleep mode does not use a clock source. the ulpwu mode, on the ra0 pin, enables a slow fall- ing voltage to generate a wake-up, even from sleep, without excess current consumption. (see section 4.7 ?ultra low-power wake-up? .) the power-managed modes include several power- saving features offered on previous pic ? devices. one is the clock switching feature, offered in other pic18 devices. this feature allows the controller to use the sosc oscillator instead of the primary one. another power-saving feature is sleep mode, offered by all pic devices, where all device clocks are stopped. 4.1 selecting power-managed modes selecting a power-managed mode requires two decisions: ? will the cpu be clocked or not ? what will be the clock source the idlen bit (osccon<7>) controls cpu clocking, while the scs<1:0> bits (osccon<1:0>) select the clock source. the individual modes, bit settings, clock sources and affected modules are summarized in tab l e 4 - 1 . 4.1.1 clock sources the scs<1:0> bits select one of three clock sources for power-managed modes. those sources are: ? the primary clock as defined by the fosc<3:0> configuration bits ? the secondary clock (the sosc oscillator) ? the internal oscillator block (for lf-intosc modes) 4.1.2 entering power-managed modes switching from one power-managed mode to another begins by loading the osccon register. the scs<1:0> bits select the clock source and determine which run or idle mode is used. changing these bits causes an immediate switch to the new clock source, assuming that it is running. the switch may also be subject to clock transition delays. these considerations are discussed in section 4.1.3 ?clock transitions and status indicators? and subsequent sections. entering the power-managed idle or sleep modes is triggered by the execution of a sleep instruction. the actual mode that results depends on the status of the idlen bit. depending on the current and impending mode, a change to a power-managed mode does not always require setting all of the previously discussed bits. many transitions can be done by changing the oscillator select bits, or changing the idlen bit, prior to issuing a sleep instruction. if the idlen bit is already configured as desired, it may only be necessary to perform a sleep instruction to switch to the desired mode. table 4-1: power- managed modes mode osccon bits module clocking available clock and oscillator source idlen<7> (1) scs<1:0> cpu peripherals sleep 0 n/a off off none ? all clocks are disabled pri_run n/a 00 clocked clocked primary ? xt, lp, hs, ec, rc and pll modes. this is the normal, full-power execution mode. sec_run n/a 01 clocked clocked secondary ? sosc oscillator rc_run n/a 1x clocked clocked internal oscillator block (2) pri_idle 100 off clocked primary ? lp, xt, hs, rc, ec sec_idle 101 off clocked secondary ? sosc oscillator rc_idle 11x off clocked internal oscillator block (2) note 1: idlen reflects its value when the sleep instruction is executed. 2: includes intosc (hf-intosc and mg-intosc) and intosc postscaler, as well as the lf-intosc source.
pic18f66k80 family ds39977d-page 68 ? 2011 microchip technology inc. 4.1.3 clock transitions and status indicators the length of the transition between clock sources is the sum of two cycles of the old clock source and three to four cycles of the new clock source. this formula assumes that the new clock source is stable. the hf- intosc and mf-intosc are termed as intosc in this chapter. three bits indicate the current clock source and its status, as shown in ta bl e 4 - 2 . the three bits are: ? osts (osccon<3>) ? hfiofs (osccon<2>) ? soscrun (osccon2<6>) when the osts bit is set, the primary clock is providing the device clock. when the hfiofs or mfiofs bit is set, the intosc output is providing a stable clock source to a divider that actually drives the device clock. when the soscrun bit is set, the sosc oscillator is providing the clock. if none of these bits are set, either the lf-intosc clock source is clocking the device or the intosc source is not yet stable. if the internal oscillator block is configured as the primary clock source by the fosc<3:0> configuration bits (config1h<3:0>). then, the osts and hfiofs or mfiofs bits can be set when in pri_run or pri_idle mode. this indicates that the primary clock (intosc output) is generating a stable output. enter- ing another intosc power-managed mode at the same frequency would clear the osts bit. 4.1.4 multiple sleep commands the power-managed mode that is invoked with the sleep instruction is determined by the setting of the idlen bit at the time the instruction is executed. if another sleep instruction is executed, the device will enter the power-managed mode specified by idlen at that time. if idlen has changed, the device will enter the new power-managed mode specified by the new setting. 4.2 run modes in the run modes, clocks to both the core and peripherals are active. the difference between these modes is the clock source. 4.2.1 pri_run mode the pri_run mode is the normal, full-power execu- tion mode of the microcontroller. this is also the default mode upon a device reset, unless two-speed start-up is enabled. (for details, see section 28.4 ?two-speed start-up? .) in this mode, the osts bit is set. the hfiofs or mfiofs bit may be set if the internal oscillator block is the primary clock source. (see section 3.2 ?control registers? .) 4.2.2 sec_run mode the sec_run mode is the compatible mode to the ?clock-switching? feature offered in other pic18 devices. in this mode, the cpu and peripherals are clocked from the sosc oscillator. this enables lower power consumption while retaining a high-accuracy clock source. sec_run mode is entered by setting the scs<1:0> bits to ? 01 ?. the device clock source is switched to the sosc oscillator (see figure 4-1 ), the primary oscillator is shut down, the soscrun bit (osccon2<6>) is set and the osts bit is cleared. on transitions from sec_run mode to pri_run mode, the peripherals and cpu continue to be clocked from the sosc oscillator while the primary clock is started. when the primary clock becomes ready, a clock switch back to the primary clock occurs (see figure 4-2 ). when the clock switch is complete, the soscrun bit is cleared, the osts bit is set and the primary clock is providing the clock. the idlen and scs bits are not affected by the wake-up and the sosc oscillator continues to run. table 4-2: system clock indicator main clock source osts hfiofs or mfiofs soscrun primary oscillator 10 0 intosc (hf-intosc or mf-intosc) 01 0 secondary oscillator 00 1 mf-intosc or hf-intosc as primary clock source 11 0 lf-intosc is running or intosc is not yet stable 00 0 note 1: caution should be used when modifying a single ircf bit. at a lower v dd , it is possible to select a higher clock speed than is supportable by that v dd . improper device operation may result if the v dd / f osc specifications are violated. 2: executing a sleep instruction does not necessarily place the device into sleep mode. it acts as the trigger to place the controller into either the sleep mode, or one of the idle modes, depending on the setting of the idlen bit. note: the sosc oscillator can be enabled by setting the soscgo bit (osccon2<3>). if this bit is set, the clock switch to the sec_run mode can switch immediately once scs<1:0> are set to ? 01 ?.
? 2011 microchip technology inc. ds39977d-page 69 pic18f66k80 family figure 4-1: transition timing for entry to sec_run mode figure 4-2: transition timing from sec_run mode to pri_run mode (hspll) 4.2.3 rc_run mode in rc_run mode, the cpu and peripherals are clocked from the internal oscillator block using the intosc multiplexer. in this mode, the primary clock is shut down. when using the lf-intosc source, this mode provides the best power conservation of all the run modes, while still executing code. it works well for user applications which are not highly timing-sensitive or do not require high-speed clocks at all times. if the primary clock source is the internal oscillator block ? either lf-intosc or intosc (mf-intosc or hf-intosc) ? there are no distinguishable differences between the pri_run and rc_run modes during execution. entering or exiting rc_run mode, how- ever, causes a clock switch delay. therefore, if the primary clock source is the internal oscillator block, using rc_run mode is not recommended. this mode is entered by setting the scs1 bit to ? 1 ?. to maintain software compatibility with future devices, it is recommended that the scs0 bit also be cleared, even though the bit is ignored. when the clock source is switched to the intosc multiplexer (see figure 4-3 ), the primary oscillator is shut down and the osts bit is cleared. the ircf bits may be modified at any time to immediately change the clock speed. q4 q3 q2 osc1 peripheral program q1 sosci q1 counter clock cpu clock pc + 2 pc 123 n-1n clock transition (1) q4 q3 q2 q1 q3 q2 pc + 4 note 1: clock transition typically occurs within 2-4 t osc . q1 q3 q4 osc1 peripheral program pc sosc pll clock q1 pc + 4 q2 output q3 q4 q1 cpu clock pc + 2 clock counter q2 q2 q3 note1: t ost = 1024 t osc ; t pll = 2 ms (approx). these intervals are not shown to scale. 2: clock transition typically occurs within 2-4 t osc . scs<1:0> bits changed t pll (1) 12 n-1n clock osts bit set transition (2) t ost (1) note: caution should be used when modifying a single ircf bit. at a lower v dd , it is possible to select a higher clock speed than is supportable by that v dd . improper device operation may result if the v dd / f osc specifications are violated.
pic18f66k80 family ds39977d-page 70 ? 2011 microchip technology inc. if the ircf bits and the intsrc bit are all clear, the intosc output (hf-into sc/mf-intosc) is not enabled and the hfiofs and mfiofs bits will remain clear. there will be no indication of the current clock source. the lf-intosc source is providing the device clocks. if the ircf bits are changed from all clear (thus, enabling the intosc output) or if intsrc or mfiosel is set, the hfiofs or mfiofs bit is set after the intosc output becomes stable. for details, see table 4-3 . table 4-3: internal oscillator frequency stability bits clocks to the device continue while the intosc source stabilizes after an interval of t iobst (parameter 39, table 31-11 ). if the ircf bits were previously at a non-zero value, or if intsrc was set before setting scs1 and the intosc source was already stable, the hfiofs or mfiofs bit will remain set. on transitions from rc_run mode to pri_run mode, the device continues to be clocked from the intosc multiplexer while the primary clock is started. when the primary clock becomes ready, a clock switch to the primary clock occurs (see figure 4-4 ). when the clock switch is complete, the hfiofs or mfiofs bit is cleared, the osts bit is set and the primary clock is providing the device clock. the idlen and scs bits are not affected by the switch. the lf-intosc source will continue to run if either the wdt or the fail-safe clock monitor (fscm) is enabled. ircf<2:0> intsrc mfiosel status of mfiofs or hfiofs when intosc is stable 000 0 x mfiofs = 0 , hfiofs = 0 and clock source is lf-intosc 000 1 0 mfiofs = 0 , hfiofs = 1 and clock source is hf-intosc 000 1 1 mfiofs = 1 , hfiofs = 0 and clock source is mf-intosc non-zero x0 mfiofs = 0 , hfiofs = 1 and clock source is hf-intosc non-zero x1 mfiofs = 1 , hfiofs = 0 and clock source is mf-intosc
? 2011 microchip technology inc. ds39977d-page 71 pic18f66k80 family figure 4-3: transition timing to rc_run mode figure 4-4: transition timing from rc_run mode to pri_run mode q4 q3 q2 osc1 peripheral program q1 lf-intosc q1 counter clock cpu clock pc + 2 pc 123 n-1n clock transition (1) q4 q3 q2 q1 q3 q2 pc + 4 note 1: clock transition typically occurs within 2-4 t osc . q1 q3 q4 osc1 peripheral program pc intosc pll clock q1 pc + 4 q2 output q3 q4 q1 cpu clock pc + 2 clock counter q2 q2 q3 note1: t ost = 1024 t osc ; t pll = 2 ms (approx). these intervals are not shown to scale. 2: clock transition typically occurs within 2-4 t osc . scs<1:0> bits changed t pll (1) 12 n-1n clock osts bit set transition (2) multiplexer t ost (1)
pic18f66k80 family ds39977d-page 72 ? 2011 microchip technology inc. 4.3 sleep mode the power-managed sleep mode in the pic18f66k80 family of devices is identical to the legacy sleep mode offered in all other pic devices. it is entered by clearing the idlen bit (the default state on device reset) and executing the sleep instruction. this shuts down the selected oscillator ( figure 4-5 ). all clock source status bits are cleared. entering sleep mode from any other mode does not require a clock switch. this is because no clocks are needed once the controller has entered sleep. if the wdt is selected, the lf-intosc source will continue to operate. if the sosc oscillator is enabled, it will also continue to run. when a wake event occurs in sleep mode (by interrupt, reset or wdt time-out), the device will not be clocked until the clock source selected by the scs<1:0> bits becomes ready (see figure 4-6 ). alternately, the device will be clocked from the internal oscillator block if either the two-speed start-up or the fail-safe clock monitor is enabled (see section 28.0 ?special features of the cpu? ). in either case, the osts bit is set when the primary clock is providing the device clocks. the idlen and scs bits are not affected by the wake-up. 4.4 idle modes the idle modes allow the controller?s cpu to be selectively shut down while the peripherals continue to operate. selecting a particular idle mode allows users to further manage power consumption. if the idlen bit is set to a ? 1 ? when a sleep instruction is executed, the peripherals will be clocked from the clock source selected using the scs<1:0> bits. the cpu, however, will not be clocked. the clock source status bits are not affected. this approach is a quick method to switch from a given run mode to its corresponding idle mode. if the wdt is selected, the lf-intosc source will continue to operate. if the sosc oscillator is enabled, it will also continue to run. since the cpu is not executing instructions, the only exits from any of the idle modes are by interrupt, wdt time-out or a reset. when a wake event occurs, cpu execution is delayed by an interval of t csd (parameter 38, ta b l e 3 1 - 11 ) while it becomes ready to execute code. when the cpu begins executing code, it resumes with the same clock source for the current idle mode. for example, when waking from rc_idle mode, the internal oscillator block will clock the cpu and peripherals (in other words, rc_run mode). the idlen and scs bits are not affected by the wake-up. while in any idle mode or sleep mode, a wdt time- out will result in a wdt wake-up to the run mode currently specified by the scs<1:0> bits. figure 4-5: transition timing for entry to sleep mode figure 4-6: transition timing for wake from sleep (hspll) q4 q3 q2 osc1 peripheral sleep program q1 q1 counter clock cpu clock pc + 2 pc q3 q4 q1 q2 osc1 peripheral program pc pll clock q3 q4 output cpu clock q1 q2 q3 q4 q1 q2 clock counter pc + 6 pc + 4 q1 q2 q3 q4 wake event note1: t ost = 1024 t osc ; t pll = 2 ms (approx). these intervals are not shown to scale. t ost (1) t pll (1) osts bit set pc + 2
? 2011 microchip technology inc. ds39977d-page 73 pic18f66k80 family 4.4.1 pri_idle mode this mode is unique among the three low-power idle modes, in that it does not disable the primary device clock. for timing-sensitive applications, this allows for the fastest resumption of device operation with its more accurate, primary clock source, since the clock source does not have to ?warm-up? or transition from another oscillator. pri_idle mode is entered from pri_run mode by setting the idlen bit and executing a sleep instruc- tion. if the device is in another run mode, set idlen first, then clear the scs bits and execute sleep . although the cpu is disabled, the peripherals continue to be clocked from the primary clock source specified by the fosc<3:0> configuration bits. the osts bit remains set (see figure 4-7 ). when a wake event occurs, the cpu is clocked from the primary clock source. a delay of interval, t csd (parameter 39, tab l e 3 1- 11 ), is required between the wake event and the start of code execution. this is required to allow the cpu to become ready to execute instructions. after the wake-up, the osts bit remains set. the idlen and scs bits are not affected by the wake-up (see figure 4-8 ). 4.4.2 sec_idle mode in sec_idle mode, the cpu is disabled but the peripherals continue to be clocked from the sosc oscillator. this mode is entered from sec_run by set- ting the idlen bit and executing a sleep instruction. if the device is in another run mode, set the idlen bit first, then set the scs<1:0> bits to ? 01 ? and execute sleep . when the clock source is switched to the sosc oscillator, the primary oscillator is shut down, the osts bit is cleared and the soscrun bit is set. when a wake event occurs, the peripherals continue to be clocked from the sosc oscillator. after an interval of t csd following the wake event, the cpu begins executing code that is being clocked by the sosc oscillator. the idlen and scs bits are not affected by the wake-up and the sosc oscillator continues to run (see figure 4-8 ). figure 4-7: transition timing for entry to idle mode figure 4-8: transition timing for wake from idle to run mode q1 peripheral program pc pc + 2 osc1 q3 q4 q1 cpu clock clock counter q2 osc1 peripheral program pc cpu clock q1 q3 q4 clock counter q2 wake event t csd
pic18f66k80 family ds39977d-page 74 ? 2011 microchip technology inc. 4.4.3 rc_idle mode in rc_idle mode, the cpu is disabled but the periph- erals continue to be clocked from the internal oscillator block using the intosc multiplexer. this mode provides controllable power conservation during idle periods. from rc_run, this mode is entered by setting the idlen bit and executing a sleep instruction. if the device is in another run mode, first set idlen, then set the scs1 bit and execute sleep . to maintain software compatibility with future devices, it is recommended that scs0 also be cleared, though its value is ignored. the intosc multiplexer may be used to select a higher clock frequency by modifying the ircf bits before executing the sleep instruction. when the clock source is switched to the intosc multiplexer, the primary oscillator is shut down and the osts bit is cleared. if the ircf bits are set to any non-zero value, or the intsrc/mfiosel bit is set, the intosc output is enabled. the hfiofs/mfiofs bits become set, after the intosc output becomes stable, after an interval of t iobst (parameter 38, tab le 3 1- 11 ). for information on the hfiofs/mfiofs bits, see ta b l e 4 - 3 . clocks to the peripherals continue while the intosc source stabilizes. the hfiofs/mfiofs bits will remain set if the ircf bits were previously at a non- zero value or if intsrc was set before the sleep instruction was executed and the intosc source was already stable. if the ircf bits and intsrc are all clear, the intosc output will not be enabled, the hfiofs/mfiofs bits will remain clear and there will be no indication of the current clock source. when a wake event occurs, the peripherals continue to be clocked from the intosc multiplexer. after a delay of t csd (parameter 38, tab le 3 1- 11 ) following the wake event, the cpu begins executing code clocked by the intosc multiplexer. the idlen and scs bits are not affected by the wake-up. the intosc source will continue to run if either the wdt or the fail-safe clock monitor is enabled. 4.5 selective peripheral module control idle mode allows users to substantially reduce power consumption by stopping the cpu clock. even so, peripheral modules still remain clocked, and thus, con- sume power. there may be cases where the application needs what this mode does not provide: the allocation of power resources to the cpu processing with minimal power consumption from the peripherals. pic18f66k80 family devices address this requirement by allowing peripheral modules to be selectively disabled, reducing or eliminating their power consumption. this can be done with two control bits: ? peripheral enable bit, generically named xxxen ? located in the respective module?s main control register ? peripheral module disable (pmd) bit, generically named, xxxmd ? located in one of the pmdx control registers (pmd0, pmd1 or pmd2) disabling a module by clearing its xxxen bit disables the module?s functionality, but leaves its registers available to be read and written to. this reduces power consumption, but not by as much as the second approach. most peripheral modules have an enable bit. in contrast, setting the pmd bit for a module disables all clock sources to that module, reducing its power consumption to an absolute minimum. in this state, the control and status registers associated with the periph- eral are also disabled, so writes to those registers have no effect and read values are invalid. many peripheral modules have a corresponding pmd bit. there are three pmd registers in pic18f66k80 family devices: pmd0, pmd1 and pmd2. these registers have bits associated with each module for disabling or enabling a particular peripheral.
? 2011 microchip technology inc. ds39977d-page 75 pic18f66k80 family register 4-1: pmd2: peripheral module disable register 2 u-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? ? modmd ecanmd cmp2md cmp1md bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 unimplemented: read as ? 0 ? bit 3 modmd: modulator output module disable bit (1) 1 = the modulator output module is disabled. all modulator output registers are held in reset and are not writable. 0 = the modulator output module is enabled bit 2 ecanmd: enhanced can module disable bit 1 = the enhanced can module is disabled. all enhanced can registers are held in reset and are not writable. 0 = the enhanced can module is enabled bit 1 cmp2md: comparator 2 module disable bit 1 = the comparator 2 module is disabled. all comparator 2 registers are held in reset and are not writable. 0 = the comparator 2 module is enabled bit 0 cmp1md: comparator 1 module disable bit 1 = the comparator 1 module is disabled. all comparator 1 registers are held in reset and are not writable. 0 = the comparator 1 module is enabled note 1: only implemented on devices with 64 pins (pic18f6xk80, pic18lf6xk80).
pic18f66k80 family ds39977d-page 76 ? 2011 microchip technology inc. register 4-2: pmd1: peripheral module disable register 1 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 pspmd (1) ctmumd adcmd tmr4md tmr3md tmr2md tmr1md tmr0md bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 pspmd: peripheral module disable bit (1) 1 = the psp module is disabled. all psp registers are held in reset and are not writable. 0 = the psp module is enabled bit 6 ctmumd: pmd ctmu disable bit 1 = the ctmu module is disabled. all ctmu registers are held in reset and are not writable. 0 = the ctmu module is enabled bit 5 adcmd: adc module disable bit 1 = the adc module is disabled. all adc registers are held in reset and are not writable. 0 = the adc module is enabled bit 4 tmr4md: tmr4md disable bit 1 = the timer4 module is disabled. all timer4 registers are held in reset and are not writable. 0 = the timer4 module is enabled bit 3 tmr3md: tmr3md disable bit 1 = the timer3 module is disabled. all timer3 registers are held in reset and are not writable. 0 = the timer3 module is enabled bit 2 tmr2md: tmr2md disable bit 1 = the timer2 module is disabled. all timer2 registers are held in reset and are not writable. 0 = the timer2 module is enabled bit 1 tmr1md: tmr1md disable bit 1 = the timer1 module is disabled. all timer1 registers are held in reset and are not writable. 0 = the timer1 module is enabled bit 0 tmr0md: timer0 module disable bit 1 = the timer0 module is disabled. all timer0 registers are held in reset and are not writable. 0 = the timer0 module is enabled note 1: unimplemented on devices with 28-pin devices (pic18f2xk80, pic18lf2xk80).
? 2011 microchip technology inc. ds39977d-page 77 pic18f66k80 family register 4-3: pmd0: peripheral module disable register 0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ccp5md ccp4md ccp3md ccp2md ccp1md uart2md uart1md sspmd bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ccp5md: ccp5 module disable bit 1 = the ccp5 module is disabled. all ccp5 registers are held in reset and are not writable. 0 = the ccp5 module is enabled bit 6 ccp4md: ccp4 module disable bit 1 = the ccp4 module is disabled. all ccp4 registers are held in reset and are not writable. 0 = the ccp4 module is enabled bit 5 ccp3md: ccp3 module disable bit 1 = the ccp3 module is disabled. all ccp3 registers are held in reset and are not writable. 0 = the ccp3 module is enabled bit 4 ccp2md: ccp2 module disable bit 1 = the ccp2 module is disabled. all ccp2 registers are held in reset and are not writable. 0 = the ccp2 module is enabled bit 3 ccp1md: eccp1 module disable bit 1 = the eccp1 module is disabled. all eccp1 registers are held in reset and are not writable. 0 = the eccp1 module is enabled bit 2 uart2md: eusart2 module disable bit 1 = the usart2 module is disabled. all usart2 registers are held in reset and are not writable. 0 = the usart2 module is enabled bit 1 uart1md: eusart1 module disable bit 1 = the usart1 module is disabled. all usart1 registers are held in reset and are not writable. 0 = the usart1 module is enabled bit 0 sspmd: mssp module disable bit 1 = the mssp module is disabled. all ssp registers are held in reset and are not writable. 0 = the mssp module is enabled
pic18f66k80 family ds39977d-page 78 ? 2011 microchip technology inc. 4.6 exiting idle and sleep modes an exit from sleep mode or any of the idle modes is triggered by an interrupt, a reset or a wdt time-out. this section discusses the triggers that cause exits from power-managed modes. the clocking subsystem actions are discussed in each of the power-managed modes (see section 4.2 ?run modes? , section 4.3 ?sleep mode? and section 4.4 ?idle modes? ). 4.6.1 exit by interrupt any of the available interrupt sources can cause the device to exit from an idle mode or sleep mode to a run mode. to enable this functionality, an interrupt source must be enabled by setting its enable bit in one of the intconx or piex registers. the exit sequence is initiated when the corresponding interrupt flag bit is set. on all exits from idle or sleep modes by interrupt, code execution branches to the interrupt vector if the gie/ gieh bit (intcon<7>) is set. otherwise, code execu- tion continues or resumes without branching (see section 10.0 ?interrupts? ). 4.6.2 exit by wdt time-out a wdt time-out will cause different actions depending on which power-managed mode the device is in when the time-out occurs. if the device is not executing code (all idle modes and sleep mode), the time-out will result in an exit from the power-managed mode (see section 4.2 ?run modes? and section 4.3 ?sleep mode? ). if the device is executing code (all run modes), the time-out will result in a wdt reset (see section 28.2 ?watchdog timer (wdt)? ). executing a sleep or clrwdt instruction clears the wdt timer and postscaler, loses the currently selected clock source (if the fail-safe clock monitor is enabled) and modifies the ircf bits in the osccon register (if the internal oscillator block is the device clock source). 4.6.3 exit by reset normally, the device is held in reset by the oscillator start-up timer (ost) until the primary clock becomes ready. at that time, the osts bit is set and the device begins executing code. if the internal oscillator block is the new clock source, the hfiofs/mfiofs bits are set instead. the exit delay time from reset to the start of code execution depends on both the clock sources before and after the wake-up, and the type of oscillator, if the new clock source is the primary clock. exit delays are summarized in ta b l e 4 - 4 . code execution can begin before the primary clock becomes ready. if either the two-speed start-up (see section 28.4 ?two-speed start-up? ) or fail-safe clock monitor (see section 28.5 ?fail-safe clock monitor? ) is enabled, the device may begin execution as soon as the reset source has cleared. execution is clocked by the intosc multiplexer driven by the inter- nal oscillator block. execution is clocked by the internal oscillator block until either the primary clock becomes ready or a power-managed mode is entered before the primary clock becomes ready; the primary clock is then shut down. 4.6.4 exit without an oscillator start-up delay certain exits from power-managed modes do not invoke the ost at all. the two cases are: ? when in pri_idle mode, where the primary clock source is not stopped ? when the primary clock source is not any of the lp, xt, hs or hspll modes in these instances, the primary clock source either does not require an oscillator start-up delay, since it is already running (pri_idle), or normally, does not require an oscillator start-up delay (rc, ec and intio oscillator modes). however, a fixed delay of interval, t csd , following the wake event is still required when leaving sleep and idle modes to allow the cpu to prepare for execution. instruction execution resumes on the first clock cycle following this delay.
? 2011 microchip technology inc. ds39977d-page 79 pic18f66k80 family 4.7 ultra low-power wake-up the ultra low-power wake-up (ulpwu) on pin, ra0, allows a slow falling voltage to generate an interrupt without excess current consumption. to use this feature: 1. charge the capacitor on ra0 by configuring the ra0 pin to an output and setting it to ? 1 ?. 2. stop charging the capacitor by configuring ra0 as an input. 3. discharge the capacitor by setting the ulpen and ulpsink bits in the wdtcon register. 4. configure sleep mode. 5. enter sleep mode. when the voltage on ra0 drops below v il , the device wakes up and executes the next instruction. this feature provides a low-power technique for periodically waking up the device from sleep mode. the time-out is dependent on the discharge time of the rc circuit on ra0. when the ulpwu module wakes the device from sleep mode, the ulplvl bit (wdtcon<5>) is set. software can check this bit upon wake-up to determine the wake-up source. see example 4-1 for initializing the ulpwu module. example 4-1: ultra low-power wake-up initialization a series resistor, between ra0 and the external capacitor, provides overcurrent protection for the ra0/ cv ref /an0/ulpwu pin and enables software calibration of the time-out (see figure 4-9 ). figure 4-9: ultra low-power wake-up initialization a timer can be used to measure the charge time and discharge time of the capacitor. the charge time can then be adjusted to provide the desired delay in sleep. this technique compensates for the affects of temperature, voltage and component accuracy. the peripheral can also be configured as a simple programmable low-voltage detect (lvd) or temperature sensor. //*************************** //charge the capacitor on ra0 //*************************** trisabits.trisa0 = 0; portabits.ra0 = 1; for(i = 0; i < 10000; i++) nop(); //***************************** //stop charging the capacitor //on ra0 //***************************** trisabits.trisa0 = 1; //***************************** //enable the ultra low power //wakeup module and allow //capacitor discharge //***************************** wdtconbits.ulpen = 1; wdtconbits.ulpsink = 1; //for sleep oscconbits.idlen = 0; //enter sleep mode // sleep(); //for sleep, execution will //resume here note: for more information, see an879, ?using the microchip ultra low-power wake-up module? (ds00879). ra0/c vref /an0/ulpwu
pic18f66k80 family ds39977d-page 80 ? 2011 microchip technology inc. table 4-4: exit delay on wake-up by re set from sleep mode or any idle mode (by clock sources) power-managed mode clock source (5) exit delay clock ready status bits pri_idle mode lp, xt, hs t csd (1) osts hspll ec, rc hf-intosc (2) hfiofs mf-intosc (2) mfiofs lf-intosc none sec_idle mode sosc t csd (1) soscrun rc_idle mode hf-intosc (2) t csd (1) hfiofs mf-intosc (2) mfiofs lf-intosc none sleep mode lp, xt, hs t ost (3) osts hspll t ost + t rc (3) ec, rc t csd (1) hf-intosc (2) t iobst (4) hfiofs mf-intosc (2) mfiofs lf-intosc none note 1: t csd (parameter 38, tab le 3 1- 11 ) is a required delay when waking from sleep and all idle modes, and runs concurrently with any other required delays (see section 4.4 ?idle modes? ). 2: includes postscaler derived frequencies. on reset, intosc defaults to hf-intosc at 8 mhz. 3: t ost is the oscillator start-up timer (parameter 32, tab l e 3 1- 11 ). t rc is the pll lock-out timer (parameter f12, table 31-7 ); it is also designated as t pll . 4: execution continues during t iobst (parameter 39, table 31-11 ), the intosc stabilization period. 5: the clock source is dependent upon the settings of the scs (osccon<1:0>), ircf (osccon<6:4>) and fosc (config1h<3:0>) bits.
? 2011 microchip technology inc. ds39977d-page 81 pic18f66k80 family 5.0 reset the pic18f66k80 family devices differentiate between various kinds of reset: a) power-on reset (por) b) mclr reset during normal operation c) mclr reset during power-managed modes d) watchdog timer (wdt) reset (during execution) e) configuration mismatch (cm) reset f) programmable brown-out reset (bor) g) reset instruction h) stack full reset i) stack underflow reset this section discusses resets generated by mclr , por and bor, and covers the operation of the various start-up timers. stack reset events are covered in section 6.1.3.4 ?stack full and underflow resets? . wdt resets are covered in section 28.2 ?watchdog timer (wdt)? . a simplified block diagram of the on-chip reset circuit is shown in figure 5-1 . 5.1 rcon register device reset events are tracked through the rcon register ( register 5-1 ). the lower five bits of the regis- ter indicate that a specific reset event has occurred. in most cases, these bits can only be cleared by the event and must be set by the application after the event. the state of these flag bits, taken together, can be read to indicate the type of reset that just occurred. this is described in more detail in section 5.7 ?reset state of registers? . the rcon register also has control bits for setting interrupt priority (ipen) and software control of the bor (sboren). interrupt priority is discussed in section 10.0 ?interrupts? . bor is covered in section 5.4 ?brown-out reset (bor)? . figure 5-1: simplified block diagram of on-chip reset circuit s r q external reset mclr v dd osc1 wdt time-out v dd rise detect ost/pwrt intosc (1) por pulse ost 10-bit ripple counter pwrt chip_reset 11-bit ripple counter enable ost (2) enable pwrt note 1: this is the intosc source from the internal oscillator bl ock and is separate from the rc oscillator of the clki pin. 2: see table 5-2 for time-out situations. brown-out reset boren reset instruction stack pointer stack full/underflow reset sleep ( )_idle 1024 cycles 65.5 ms 32 ? s mclre
pic18f66k80 family ds39977d-page 82 ? 2011 microchip technology inc. register 5-1: rcon: re set control register r/w-0 r/w-1 (1) r/w-1 r/w-1 r-1 r-1 r/w-0 (2) r/w-0 ipen sboren cm ri to pd por bor bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ipen: interrupt priority enable bit 1 = enable priority levels on interrupts 0 = disable priority levels on interrupts (pic16cxxx compatibility mode) bit 6 sboren: bor software enable bit (1) if boren < 1: 0> = 01 : 1 = bor is enabled 0 = bor is disabled if boren < 1: 0> = 00 , 10 or 11 : bit is disabled and reads as ? 0 ?. bit 5 cm : configuration mismatch flag bit 1 = a configuration mismatch reset has not occurred. 0 = a configuration mismatch reset occurred. must be set in software once the reset occurs. bit 4 ri : reset instruction flag bit 1 = the reset instruction was not executed (set by firmware only) 0 = the reset instruction was executed causing a device reset (must be set in software after a brown-out reset occurs) bit 3 to : watchdog time-out flag bit 1 = set by power-up, clrwdt instruction or sleep instruction 0 = a wdt time-out occurred bit 2 pd : power-down detection flag bit 1 = set by power-up or by the clrwdt instruction 0 = set by execution of the sleep instruction bit 1 por : power-on reset status bit (2) 1 = a power-on reset has not occurred (set by firmware only) 0 = a power-on reset occurred (must be set in software after a power-on reset occurs) bit 0 bor : brown-out reset status bit 1 = a brown-out reset has not occurred (set by firmware only) 0 = a brown-out reset occurred (must be set in software after a brown-out reset occurs) note 1: if sboren is enabled, its reset state is ? 1 ?; otherwise, it is ? 0 ?. 2: the actual reset value of por is determined by the type of device reset. see the notes following this register and section 5.7 ?reset state of registers? for additional information. note 1: it is recommended that the por bit be set after a power-on reset has been detected so that subsequent power-on resets may be detected. 2: brown-out reset is said to have occurred when bor is ? 0 ? and por is ? 1 ? (assuming that por was set to ? 1 ? by software immediately after a power-on reset).
? 2011 microchip technology inc. ds39977d-page 83 pic18f66k80 family 5.2 master clear reset (mclr ) the mclr pin provides a method for triggering an external reset of the device. a reset is generated by holding the pin low. these devices have a noise filter in the mclr reset path which detects and ignores small pulses. the mclr pin is not driven low by any internal resets, including the wdt. in pic18f66k80 family devices, the mclr input can be disabled with the mclre configuration bit. when mclr is disabled, the pin becomes a digital input. see section 11.6 ?porte, trise and late registers? for more information. 5.3 power-on reset (por) a power-on reset pulse is generated on-chip whenever v dd rises above a certain threshold. this allows the device to start in the initialized state when v dd is adequate for operation. to take advantage of the por circuitry, tie the mclr pin through a resistor (1 k ? to 10 k ? ) to v dd . this will eliminate external rc components usually needed to create a power-on reset delay. a minimum rise rate for v dd is specified (parameter d004). for a slow rise time, see figure 5-2 . when the device starts normal operation (i.e., exits the reset condition), device operating parameters (voltage, frequency, temperature, etc.) must be met to ensure operation. if these conditions are not met, the device must be held in reset until the operating conditions are met. por events are captured by the por bit (rcon<1>). the state of the bit is set to ? 0 ? whenever a power-on reset occurs; it does not change for any other reset event. por is not reset to ? 1 ? by any hardware event. to capture multiple events, the user manually resets the bit to ? 1 ? in software following any power-on reset. figure 5-2: external power-on reset circuit (for slow v dd power-up) note 1: external power-on reset circuit is required only if the v dd power-up slope is too slow. the diode, d, helps discharge the capacitor quickly when v dd powers down. 2: r < 40 k ? is recommended to make sure that the voltage drop across r does not violate the device?s electric al specification. 3: r1 ? 1 k ? will limit any current flowing into mclr from external capacitor, c, in the event of mclr /v pp pin breakdown, due to electro- static discharge (esd) or electrical overstress (eos). c r1 r d v dd mclr pic18fxx80 v dd
pic18f66k80 family ds39977d-page 84 ? 2011 microchip technology inc. 5.4 brown-out reset (bor) the pic18f66k80 family has four bor power modes: ? high-power bor ? medium power bor ? low-power bor ? zero-power bor each power mode is selected by the borpwr<1:0> setting (config2l<6:5>). for low, medium and high-power bor, the module monitors the v dd depend- ing on the borv<1:0> setting (config1l<3:2>). the typical current draw ( ? ibor) for zero, low and medium power bor is 200 na, 750 na and 3 ? a, respectively. a bor event re-arms the power-on reset. it also causes a reset, depending on which of the trip levels has been set: 1.8v, 2v, 2.7v or 3v. bor is enabled by boren<1:0> (config2l<2:1>) and the sboren bit (rcon<6>). the four bor configurations are summarized in ta b l e 5 - 1 . in zero-power bor (zpbormv), the module monitors the v dd voltage and re-arms the por at about 2v. zpbormv does not cause a reset, but re-arms the por. the bor accuracy varies with its power level. the lower the power setting, the less accurate the bor trip levels are. therefore, the high-power bor has the highest accuracy and the low-power bor has the lowest accu- racy. the trip levels (b vdd , parameter d005), current consumption ( section 31.2 ?dc characteristics: power-down and supply current pic18f66k80 family (industrial/extended)? ) and time required below b vdd (tbor, parameter 35) can all be found in section 31.0 ?electrical characteristics? . 5.4.1 software enabled bor when boren<1:0> = 01 , the bor can be enabled or disabled by the user in software. this is done with the control bit, sboren (rcon<6>). setting sboren enables the bor to function as previously described. clearing sboren disables the bor entirely. the sboren bit operates only in this mode; otherwise it is read as ? 0 ?. placing the bor under software control gives the user the additional flexibility of tailoring the application to its environment without having to reprogram the device to change bor configuration. it also allows the user to tailor device power consumption in software by elimi- nating the incremental current that the bor consumes. while the bor current is typically very small, it may have some impact in low-power applications. 5.4.2 detecting bor when brown-out reset is enabled, the bor bit always resets to ? 0 ? on any brown-out reset or power-on reset event. this makes it difficult to determine if a brown-out reset event has occurred just by reading the state of bor alone. a more reliable method is to simultaneously check the state of both por and bor . this assumes that the por bit is reset to ? 1 ? in software immediately after any power-on reset event. if bor is ? 0 ? while por is ? 1 ?, it can be reliably assumed that a brown-out reset event has occurred. 5.4.3 disabling bor in sleep mode when boren<1:0> = 10 , the bor remains under hardware control and operates as previously described. whenever the device enters sleep mode, however, the bor is automatically disabled. when the device returns to any other operating mode, bor is automatically re-enabled. this mode allows for applications to recover from brown-out situations, while actively executing code, when the device requires bor protection the most. at the same time, it saves additional power in sleep mode by eliminating the small incremental bor current. table 5-1: bor configurations note: even when bor is under software con- trol, the brown-out reset voltage level is still set by the borv<1:0> configuration bits; it cannot be changed in software. bor configuration status of sboren (rcon<6>) bor operation boren1 boren0 00 unavailable bor disabled; must be enabled by reprogramming the configuration bits. 01 available bor enabled in software; operation controlled by sboren. 10 unavailable bor enabled in hardware in run and idle modes; disabled during sleep mode. 11 unavailable bor enabled in hardware; must be disabled by reprogramming the configuration bits.
? 2011 microchip technology inc. ds39977d-page 85 pic18f66k80 family 5.5 configuration mismatch (cm) the configuration mismatch (cm) reset is designed to detect, and attempt to recover from, random memory corrupting events. these include electrostatic discharge (esd) events, which can cause widespread, single bit changes throughout the device and result in catastrophic failure. in pic18fxxkxx flash devices, the device configura- tion registers (located in the configuration memory space) are continuously monitored during operation by comparing their values to complimentary shadow reg- isters. if a mismatch is detected between the two sets of registers, a cm reset automatically occurs. these events are captured by the cm bit (rcon<5>) being set to ? 0 ?. this bit does not change for any other reset event. a cm reset behaves similarly to a master clear reset, reset instruction, wdt time-out or stack event resets. as with all hard and power reset events, the device configuration words are reloaded from the flash configuration words in program memory as the device restarts. 5.6 device reset timers pic18f66k80 family devices incorporate three sepa- rate on-chip timers that help regulate the power-on reset process. their main function is to ensure that the device clock is stable before code is executed. these timers are: ? power-up timer (pwrt) ? oscillator start-up timer (ost) ? pll lock time-out 5.6.1 power-up timer (pwrt) the power-up timer (pwrt) of the pic18f66k80 family devices is an 11-bit counter which uses the intosc source as the clock input. this yields an approximate time interval of 2048 x 32 ? s=65.6ms. while the pwrt is counting, the device is held in reset. the power-up time delay depends on the intosc clock and will vary from chip-to-chip due to temperature and process variation. see dc parameter 33 for details. the pwrt is enabled by clearing the pwrten configuration bit.
pic18f66k80 family ds39977d-page 86 ? 2011 microchip technology inc. 5.6.2 oscillator start-up timer (ost) the oscillator start-up timer (ost) provides a 1024 oscillator cycle (from osc1 input) delay after the pwrt delay is over (parameter 33). this ensures that the crystal oscillator or resonator has started and stabilized. the ost time-out is invoked only for xt, lp, hs and hspll modes and only on power-on reset or on exit from most power-managed modes. 5.6.3 pll lock time-out with the pll enabled in its pll mode, the time-out sequence following a power-on reset is slightly differ- ent from other oscillator modes. a separate timer is used to provide a fixed time-out that is sufficient for the pll to lock to the main oscillator frequency. this pll lock time-out (t pll ) is typically 2 ms and follows the oscillator start-up time-out. 5.6.4 time-out sequence on power-up, the time-out sequence is as follows: 1. after the por pulse has cleared, pwrt time-out is invoked (if enabled). 2. then, the ost is activated. the total time-out will vary based on oscillator configu- ration and the status of the pwrt. figure 5-3 , figure 5-4 , figure 5-5 , figure 5-6 and figure 5-7 all depict time-out sequences on power-up, with the power-up timer enabled and the device operating in hs oscillator mode. figures 5-3 through 5-6 also apply to devices operating in xt or lp modes. for devices in rc mode and with the pwrt disabled, on the other hand, there will be no time-out at all. since the time-outs occur from the por pulse, if mclr is kept low long enough, all time-outs will expire. bring- ing mclr high will begin execution immediately ( figure 5-5 ). this is useful for testing purposes or to synchronize more than one pic18fxxxx device operating in parallel. table 5-2: time-out in various situations figure 5-3: time-out sequ ence on power-up (mclr tied to v dd , v dd rise < t pwrt ) oscillator configuration power-up and brown-out exit from power-managed mode pwrten = 0 pwrten = 1 hspll 66 ms (1) + 1024 t osc + 2 ms (2) 1024 t osc + 2 ms (2) 1024 t osc + 2 ms (2) hs, xt, lp 66 ms (1) + 1024 t osc 1024 t osc 1024 t osc ec, ecio 66 ms (1) ?? rc, rcio 66 ms (1) ?? intio1, intio2 66 ms (1) ?? note 1: 66 ms (65.5 ms) is the nominal power-up timer (pwrt) delay. 2: 2 ms is the nominal time required for the pll to lock. t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset
? 2011 microchip technology inc. ds39977d-page 87 pic18f66k80 family figure 5-4: time-out sequ ence on power-up (mclr not tied to v dd ): case 1 figure 5-5: time-out sequ ence on power-up (mclr not tied to v dd ): case 2 figure 5-6: slow rise time (mclr tied to v dd , v dd rise > t pwrt ) t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset v dd mclr internal por pwrt time-out ost time-out internal reset t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset 0v 1v 5v t pwrt t ost
pic18f66k80 family ds39977d-page 88 ? 2011 microchip technology inc. figure 5-7: time-out sequence on por w/pll enabled (mclr tied to v dd ) t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset pll time-out t pll note: t ost = 1024 clock cycles. t pll ? 2 ms max. first three stages of the pwrt timer.
? 2011 microchip technology inc. ds39977d-page 89 pic18f66k80 family 5.7 reset state of registers most registers are unaffected by a reset. their status is unknown on a power-on reset and unchanged by all other resets. the other registers are forced to a ?reset state? depending on the type of reset that occurred. most registers are not affected by a wdt wake-up, since this is viewed as the resumption of normal oper- ation. status bits from the rcon register, ri , to , pd , cm , por and bor , are set or cleared differently in dif- ferent reset situations, as indicated in tab le 5 -3 . these bits are used in software to determine the nature of the reset. table 5-4 describes the reset states for all of the special function registers. these are categorized by power-on and brown-out resets, master clear and wdt resets and wdt wake-ups. table 5-3: status bits, their significanc e and the initialization condition for rcon register condition program counter (1) rcon register stkptr register sboren cm ri to pd por bor stkful stkunf power-on reset 0000h 1 111100 0 0 reset instruction 0000h u (2) u0uuuu u u brown-out reset 0000h u (2) 1111u0 u u mclr reset during power-managed run modes 0000h u (2) uu1uuu u u mclr reset during power-managed idle modes and sleep mode 0000h u (2) uu10uu u u wdt time-out during full power or power-managed run modes 0000h u (2) uu0uuu u u mclr reset during full-power execution 0000h u (2) uuuuuu u u stack full reset (stvren = 1 ) 0000h u (2) uuuuuu 1 u stack underflow reset (stvren = 1 ) 0000h u (2) uuuuuu u 1 stack underflow error (not an actual reset, stvren = 0 ) 0000h u (2) uuuuuu u 1 wdt time-out during power-managed idle or sleep modes pc + 2 u (2) uu00uu u u interrupt exit from power-managed modes pc + 2 u (2) uuu0uu u u legend: u = unchanged note 1: when the wake-up is due to an interrupt and the gieh or giel bits are set, the pc is loaded with the interrupt vector (008h or 0018h). 2: reset state is ? 1 ? for por and unchanged for all other resets when software bor is enabled (boren<1:0> configuration bits = 01 and sboren = 1 ); otherwise, the reset state is ? 0 ?.
pic18f66k80 family ds39977d-page 90 ? 2011 microchip technology inc. table 5-4: initialization co nditions for all registers register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt tosu pic18f2xk80 pic18f4xk80 pic18f6xk80 ---0 0000 ---0 0000 ---0 uuuu (3) tosh pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu (3) tosl pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu (3) stkptr pic18f2xk80 pic18f4xk80 pic18f6xk80 00-0 0000 uu-0 0000 uu-u uuuu (3) pclatu pic18f2xk80 pic18f4xk80 pic18f6xk80 ---0 0000 ---0 0000 ---u uuuu pclath pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu pcl pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 pc + 2 (2) tblptru pic18f2xk80 pic18f4xk80 pic18f6xk80 --00 0000 --00 0000 --uu uuuu tblptrh pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu tblptrl pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu tablat pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu prodh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu prodl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu intcon pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 000x 0000 000u uuuu uuuu (1) intcon2 pic18f2xk80 pic18f4xk80 pic18f6xk80 1111 -1-1 1111 -1-1 uuuu -u-u (1) intcon3 pic18f2xk80 pic18f4xk80 pic18f6xk80 11x0 0x00 11x0 0x00 uuuu uuuu (1) indf0 pic18f2xk80 pic18f4xk80 pic18f6xk80 n/a n/a n/a postinc0 pic18f2xk80 pic18f4xk80 pic18f6xk80 n/a n/a n/a postdec0 pic18f2xk80 pic18f4xk80 pic18f6xk80 n/a n/a n/a preinc0 pic18f2xk80 pic18f4xk80 pic18f6xk80 n/a n/a n/a plusw0 pic18f2xk80 pic18f4xk80 pic18f6xk80 n/a n/a n/a fsr0h pic18f2xk80 pic18f4xk80 pic18f6xk80 ---- xxxx ---- uuuu ---- uuuu fsr0l pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu wreg pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu indf1 pic18f2xk80 pic18f4xk80 pic18f6xk80 n/a n/a n/a postinc1 pic18f2xk80 pic18f4xk80 pic18f6xk80 n/a n/a n/a postdec1 pic18f2xk80 pic18f4xk80 pic18f6xk80 n/a n/a n/a preinc1 pic18f2xk80 pic18f4xk80 pic18f6xk80 n/a n/a n/a plusw1 pic18f2xk80 pic18f4xk80 pic18f6xk80 n/a n/a n/a fsr1h pic18f2xk80 pic18f4xk80 pic18f6xk80 ---- xxxx ---- uuuu ---- uuuu fsr1l pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu bsr pic18f2xk80 pic18f4xk80 pic18f6xk80 ---- 0000 ---- 0000 ---- uuuu indf2 pic18f2xk80 pic18f4xk80 pic18f6xk80 n/a n/a n/a legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 5-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
? 2011 microchip technology inc. ds39977d-page 91 pic18f66k80 family postinc2 pic18f2xk80 pic18f4xk80 pic18f6xk80 n/a n/a n/a postdec2 pic18f2xk80 pic18f4xk80 pic18f6xk80 n/a n/a n/a preinc2 pic18f2xk80 pic18f4xk80 pic18f6xk80 n/a n/a n/a plusw2 pic18f2xk80 pic18f4xk80 pic18f6xk80 n/a n/a n/a fsr2h pic18f2xk80 pic18f4xk80 pic18f6xk80 ---- xxxx ---- uuuu ---- uuuu fsr2l pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu status pic18f2xk80 pic18f4xk80 pic18f6xk80 ---x xxxx ---u uuuu ---u uuuu tmr0h pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 uuuu uuuu uuuu uuuu tmr0l pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu t0con pic18f2xk80 pic18f4xk80 pic18f6xk80 1111 1111 1111 1111 uuuu uuuu osccon pic18f2xk80 pic18f4xk80 pic18f6xk80 0100 q000 0100 00q0 uuuu uuqu osccon2 pic18f2xk80 pic18f4xk80 pic18f6xk80 -x-x x-xx -0-0 0-01 -u-u u-uu wdtcon pic18f2xk80 pic18f4xk80 pic18f6xk80 0-x0 -xx0 0-x0 -xx0 u-u0 -uu0 rcon (4) pic18f2xk80 pic18f4xk80 pic18f6xk80 0111 11q0 0111 qquu uuuu qquu tmr1h pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu tmr1l pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu t1con pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 u0uu uuuu uuuu uuuu tmr2 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu pr2 pic18f2xk80 pic18f4xk80 pic18f6xk80 1111 1111 1111 1111 uuuu uuuu t2con pic18f2xk80 pic18f4xk80 pic18f6xk80 -000 0000 -000 0000 -uuu uuuu sspbuf pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 uuuu uuuu uuuu uuuu sspadd pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu sspstat pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu sspcon1 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu sspcon2 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu adresh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu adresl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu adcon0 pic18f2xk80 pic18f4xk80 pic18f6xk80 -000 0000 -000 0000 -uuu uuuu adcon1 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0qqq 0000 0qqq uuuu uuuu adcon2 pic18f2xk80 pic18f4xk80 pic18f6xk80 0-00 0000 0-00 0000 u-uu uuuu eccp1as pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 xxxx xxxx ccpr1h pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu ccpr1l pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu ccp1con pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu table 5-4: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 5-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
pic18f66k80 family ds39977d-page 92 ? 2011 microchip technology inc. txsta2 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0010 0000 0010 uuuu uuuu baudcon2 pic18f2xk80 pic18f4xk80 pic18f6xk80 01x0 0-00 01x0 0-00 uuuu u-uu ipr4 pic18f2xk80 pic18f4xk80 pic18f6xk80 1111 -111 1111 -111 uuuu -uuu pir4 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 -000 0000 -000 uuuu -uuu pie4 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 -000 0000 -000 uuuu -uuu cvrcon pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu cmstat pic18f2xk80 pic18f4xk80 pic18f6xk80 11-- ---- 11-- ---- uu-- ---- tmr3h pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu tmr3l pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu t3con pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu t3gcon pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0x00 0000 0x00 uuuu u-uu spbrg1 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu rcreg1 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu txreg1 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx 0000 0000 uuuu uuuu txsta1 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0010 0000 0010 uuuu uuuu rcsta1 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 000x 0000 000x uuuu uuuu t1gcon pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0x00 0000 0x00 uuuu u-uu pr4 pic18f2xk80 pic18f4xk80 pic18f6xk80 1111 1111 1111 1111 uuuu uuuu hlvdcon pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu baudcon1 pic18f2xk80 pic18f4xk80 pic18f6xk80 01x0 0-00 01x0 0-00 uuuu u-uu rcsta2 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 000x 0000 000x uuuu uuuu ipr3 pic18f2xk80 pic18f4xk80 pic18f6xk80 --11 111- --11 111- --uu uuu- pir3 pic18f2xk80 pic18f4xk80 pic18f6xk80 --x0 xxx- --x0 xxx- --uu uuu- pie3 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu ipr2 pic18f2xk80 pic18f4xk80 pic18f6xk80 1--- 111x 1--- 111x u--- uuuu pir2 pic18f2xk80 pic18f4xk80 pic18f6xk80 0--- 000x 0--- 000x u--- uuuu (1) pie2 pic18f2xk80 pic18f4xk80 pic18f6xk80 0--- 000x 0--- 0000 u--- uuuu ipr1 pic18f2xk80 pic18f4xk80 pic18f6xk80 1111 1111 1111 1111 uuuu uuuu pic18f2xk80 pic18f4xk80 pic18f6xk80 -111 1111 -111 1111 -uuu uuuu pir1 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu (1) pic18f2xk80 pic18f4xk80 pic18f6xk80 -000 0000 -000 0000 -uuu uuuu pie1 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu pic18f2xk80 pic18f4xk80 pic18f6xk80 -000 0000 -000 0000 -uuu uuuu pstr1con pic18f2xk80 pic18f4xk80 pic18f6xk80 00-0 0001 xx-x xxxx ? table 5-4: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 5-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
? 2011 microchip technology inc. ds39977d-page 93 pic18f66k80 family osctune pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu refocon pic18f2xk80 pic18f4xk80 pic18f6xk80 0-00 0000 0-00 0000 u-uu uuuu ccptmrs pic18f2xk80 pic18f4xk80 pic18f6xk80 ---1 1111 ---1 1111 ---u uuuu trisg pic18f2xk80 pic18f4xk80 pic18f6xk80 ---1 111 ---1 1111 ---u uuuu trisf pic18f2xk80 pic18f4xk80 pic18f6xk80 1111 1111 1111 1111 uuuu uuuu trise pic18f2xk80 pic18f4xk80 pic18f6xk80 1111 -111 1111 -111 uuuu -uuu trisd pic18f2xk80 pic18f4xk80 pic18f6xk80 1111 1111 1111 1111 uuuu uuuu trisc pic18f2xk80 pic18f4xk80 pic18f6xk80 1111 1111 1111 1111 uuuu uuuu trisb pic18f2xk80 pic18f4xk80 pic18f6xk80 1111 1111 1111 1111 uuuu uuuu trisa (5) pic18f2xk80 pic18f4xk80 pic18f6xk80 111- 1111 (5) 111- 1111 (5) uuu- uuuu (5) odcon pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu slrcon pic18f2xk80 pic18f4xk80 pic18f6xk80 -111 1111 -111 1111 -111 1111 latg pic18f2xk80 pic18f4xk80 pic18f6xk80 ---x xxxx ---x xxxx ---u uuuu latf pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx -xxx xxxx -xxx uuuu -uuu late pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx xxxx xxxx uuuu uuuu latd pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx xxxx xxxx uuuu uuuu latc pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx xxxx xxxx uuuu uuuu latb pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx xxxx xxxx uuuu uuuu lata (5) pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- xxxx (5) xxx- xxxx (5) uuu- uuuu (5) t4con pic18f2xk80 pic18f4xk80 pic18f6xk80 -000 0000 -000 0000 -uuu uuuu tmr4 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu portg pic18f2xk80 pic18f4xk80 pic18f6xk80 ---x xxxx ---x xxxx ---u uuuu portf pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx xxxx xxxx uuuu uuuu porte pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx xxxx xxxx uuuu uuuu portd pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx xxxx xxxx uuuu uuuu portc pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx xxxx xxxx uuuu uuuu portb pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx xxxx xxxx uuuu uuuu porta (5) pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- xxxx (5) xxx- xxxx (5) uuu- uuuu (5) eecon1 pic18f2xk80 pic18f4xk80 pic18f6xk80 xx-0 x000 uu-0 u000 uu-u uuuu eecon2 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu spbrgh1 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu spbrgh2 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu spbrg2 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu rcreg2 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu table 5-4: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 5-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
pic18f66k80 family ds39977d-page 94 ? 2011 microchip technology inc. txreg2 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu ipr5 pic18f2xk80 pic18f4xk80 pic18f6xk80 1111 1111 1111 1111 uuuu uuuu pir5 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu pie5 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu eeadrh pic18f2xk80 pic18f4xk80 pic18f6xk80 ---- --00 ---- --00 ---- --00 eeadr pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu eedata pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu ecancon pic18f2xk80 pic18f4xk80 pic18f6xk80 0001 0000 0001 0000 uuuu uuuu comstat pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu ciocon pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 ---0 0000 ---0 uuuu ---u cancon pic18f2xk80 pic18f4xk80 pic18f6xk80 1000 0000 1000 0000 uuuu uuuu canstat pic18f2xk80 pic18f4xk80 pic18f6xk80 1000 0000 1000 0000 uuuu uuuu rxb0d7 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb0d6 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb0d5 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb0d4 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb0d3 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb0d2 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb0d1 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb0d0 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb0dlc pic18f2xk80 pic18f4xk80 pic18f6xk80 0xxx xxxx 0uuu uuuu uuuu uuuu rxb0eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb0eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb0sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx x-xx uuuu u-uu uuuu u-uu rxb0sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb0con pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu rxb0con pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu cm1con pic18f2xk80 pic18f4xk80 pic18f6xk80 0001 1111 0001 1111 uuuu uuuu cm2con pic18f2xk80 pic18f4xk80 pic18f6xk80 0001 1111 0001 1111 uuuu uuuu ancon0 pic18f2xk80 pic18f4xk80 pic18f6xk80 1111 1111 1111 1111 uuuu uuuu ancon1 pic18f2xk80 pic18f4xk80 pic18f6xk80 -111 1111 -111 1111 -uuu uuuu wpub pic18f2xk80 pic18f4xk80 pic18f6xk80 1111 1111 1111 1111 uuuu uuuu iocb pic18f2xk80 pic18f4xk80 pic18f6xk80 1111 ---- 1111 ---- uuuu ---- pmd0 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu table 5-4: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 5-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
? 2011 microchip technology inc. ds39977d-page 95 pic18f66k80 family pmd1 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu pmd2 pic18f2xk80 pic18f4xk80 pic18f6xk80 ---- 0000 ---- 0000 ---- uuuu padcfg1 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 ---0 0000 ---0 uuuu ---u ctmuconh pic18f2xk80 pic18f4xk80 pic18f6xk80 0-00 0000 0-00 0000 u-uu uuuu ctmuconl pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu ctmuiconh pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu ccpr2h pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx xxxx xxxx uuuu uuuu ccpr2l pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx xxxx xxxx uuuu uuuu ccp2con pic18f2xk80 pic18f4xk80 pic18f6xk80 --00 0000 --00 0000 --uu uuuu ccpr3h pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx xxxx xxxx uuuu uuuu ccpr3l pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx xxxx xxxx uuuu uuuu ccp3con pic18f2xk80 pic18f4xk80 pic18f6xk80 --00 0000 --00 0000 --uu uuuu ccpr4h pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx xxxx xxxx uuuu uuuu ccpr4l pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx xxxx xxxx uuuu uuuu ccp4con pic18f2xk80 pic18f4xk80 pic18f6xk80 --00 0000 --00 0000 --uu uuuu ccpr5h pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx xxxx xxxx uuuu uuuu ccpr5l pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx xxxx xxxx uuuu uuuu ccp5con pic18f2xk80 pic18f4xk80 pic18f6xk80 --00 0000 --00 0000 --uu uuuu pspcon pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 ---- 0000 ---- uuuu ---- mdcon pic18f2xk80 pic18f4xk80 pic18f6xk80 0010 0--0 0010 0--0 uuuu u--u mdsrc pic18f2xk80 pic18f4xk80 pic18f6xk80 0--- xxxx 0--- xxxx u--- uuuu mdcarh pic18f2xk80 pic18f4xk80 pic18f6xk80 0xx- xxxx 0xx- xxxx uuu- uuuu mdcarl pic18f2xk80 pic18f4xk80 pic18f6xk80 0xx- xxxx 0xx- xxxx uuu- uuuu cancon_ro0 pic18f2xk80 pic18f4xk80 pic18f6xk80 1000 0000 1000 0000 uuuu uuuu canstat_ro0 pic18f2xk80 pic18f4xk80 pic18f6xk80 1000 0000 1000 0000 uuuu uuuu rxb1d7 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb1d6 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb1d5 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb1d4 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb1d3 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb1d2 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb1d1 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb1d0 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb1dlc pic18f2xk80 pic18f4xk80 pic18f6xk80 0xxx xxxx 0uuu uuuu xxxx xxxx table 5-4: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 5-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
pic18f66k80 family ds39977d-page 96 ? 2011 microchip technology inc. rxb1eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb1eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb1sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx x0xx uuuu u0uu uuuu uuuu rxb1sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxb1con pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu cancon_ro1 pic18f2xk80 pic18f4xk80 pic18f6xk80 1000 0000 1000 0000 uuuu uuuu canstat_ro1 pic18f2xk80 pic18f4xk80 pic18f6xk80 1000 0000 1000 0000 uuuu uuuu txb0d7 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb0d6 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb0d5 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb0d4 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb0d3 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb0d2 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb0d1 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb0d0 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb0dlc pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx xxxx xxxx uuuu uuuu txb0eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx xxxx xxxx uuuu uuuu txb0eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx xxxx xxxx uuuu uuuu txb0sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- x-xx xxx- x-xx uuuu uuuu txb0sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx xxxx xxxx uuuu uuuu txb0con pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu u-uu cancon_ro2 pic18f2xk80 pic18f4xk80 pic18f6xk80 1000 0000 1000 0000 uuuu uuuu canstat_ro2 pic18f2xk80 pic18f4xk80 pic18f6xk80 1000 0000 1000 0000 uuuu uuuu txb1d7 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb1d6 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb1d5 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb1d4 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb1d3 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb1d2 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb1d1 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb1d0 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb1dlc pic18f2xk80 pic18f4xk80 pic18f6xk80 -x-- xxxx -u-- uuuu -u-- uuuu txb1eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb1eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu table 5-4: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 5-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
? 2011 microchip technology inc. ds39977d-page 97 pic18f66k80 family txb1sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx x-xx uuuu u-uu uuuu u-uu txb1sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb1con pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu cancon_ro3 pic18f2xk80 pic18f4xk80 pic18f6xk80 1000 0000 1000 0000 uuuu uuuu canstat_ro3 pic18f2xk80 pic18f4xk80 pic18f6xk80 1000 0000 1000 0000 uuuu uuuu txb2d7 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb2d6 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb2d5 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb2d4 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb2d3 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb2d2 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb2d1 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb2d0 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb2dlc pic18f2xk80 pic18f4xk80 pic18f6xk80 -x-- xxxx -u-- uuuu -u-- uuuu txb2eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb2eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb2sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- x-xx uuu- u-uu uuu- u-uu txb2sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu txb2con pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0-00 0000 0-00 uuuu u-uu rxm1eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxm1eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxm1sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- x-xx uuu- u-uu uuu- u-uu rxm1sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxm0eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxm0eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxm0sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- x-xx uuu- u-uu uuu- u-uu rxm0sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf5eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf5eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf5sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- x-xx uuu- u-uu uuu- u-uu rxf5sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf4eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf4eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf4sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- x-xx uuu- u-uu uuu- u-uu table 5-4: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 5-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
pic18f66k80 family ds39977d-page 98 ? 2011 microchip technology inc. rxf4sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf3eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf3eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf3sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- x-xx uuu- u-uu uuu- u-uu rxf3sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf2eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf2eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf2sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- x-xx uuu- u-uu uuu- u-uu rxf2sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf1eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf1eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf1sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- x-xx uuu- u-uu uuu- u-uu rxf1sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf0eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf0eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf0sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- x-xx uuu- u-uu uuu- u-uu rxf0sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu cancon_ro4 pic18f2xk80 pic18f4xk80 pic18f6xk80 1000 0000 1000 0000 uuuu uuuu canstat_ro4 pic18f2xk80 pic18f4xk80 pic18f6xk80 1000 0000 1000 0000 uuuu uuuu b5d7 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b5d6 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b5d5 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b5d4 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b5d3 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b5d2 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b5d1 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b5d0 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b5dlc pic18f2xk80 pic18f4xk80 pic18f6xk80 -xxx xxxx -uuu uuuu uuuu uuuu b5eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b5eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b5sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx x-xx uuuu u-uu uuuu uuuu b5sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b5con pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu cancon_ro5 pic18f2xk80 pic18f4xk80 pic18f6xk80 1000 0000 1000 0000 uuuu uuuu table 5-4: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 5-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
? 2011 microchip technology inc. ds39977d-page 99 pic18f66k80 family canstat_ro5 pic18f2xk80 pic18f4xk80 pic18f6xk80 1000 0000 1000 0000 uuuu uuuu b4d7 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b4d6 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b4d5 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b4d4 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b4d3 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b4d2 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b4d1 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b4d0 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b4dlc pic18f2xk80 pic18f4xk80 pic18f6xk80 -xxx xxxx -uuu uuuu -uuu uuuu b4eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b4eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b4sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx x-xx uuuu u-uu uuuu u-uu b4sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu xxxx xxxx b4con pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu cancon_ro6 pic18f2xk80 pic18f4xk80 pic18f6xk80 1000 0000 1000 0000 uuuu uuuu canstat_ro6 pic18f2xk80 pic18f4xk80 pic18f6xk80 1000 0000 1000 0000 uuuu uuuu b3d7 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b3d6 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b3d5 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b3d4 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b3d3 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b3d2 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b3d1 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b3d0 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b3dlc pic18f2xk80 pic18f4xk80 pic18f6xk80 -xxx xxxx -uuu uuuu -uuu uuuu b3eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b3eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b3sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx x-xx uuuu u-uu uuuu u-uu b3sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b3con pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu cancon_ro7 pic18f2xk80 pic18f4xk80 pic18f6xk80 1000 0000 1000 0000 uuuu uuuu b2d7 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b2d6 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu table 5-4: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 5-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
pic18f66k80 family ds39977d-page 100 ? 2011 microchip technology inc. b2d5 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b2d4 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b2d3 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b2d2 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b2d1 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b2d0 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b2dlc pic18f2xk80 pic18f4xk80 pic18f6xk80 -xxx xxxx -uuu uuuu -uuu uuuu b2eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b2eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b2sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx x-xx uuuu u-uu uuuu u-uu b2sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b2con pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu cancon_ro8 pic18f2xk80 pic18f4xk80 pic18f6xk80 1000 0000 1000 0000 uuuu uuuu b1d7 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b1d6 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b1d5 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b1d4 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b1d3 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b1d2 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b1d1 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b1d0 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b1dlc pic18f2xk80 pic18f4xk80 pic18f6xk80 -xxx xxxx -uuu uuuu -uuu uuuu b1eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b1eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b1sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx x-xx uuuu u-uu uuuu u-uu b1sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b1con pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu cancon_ro9 pic18f2xk80 pic18f4xk80 pic18f6xk80 1000 0000 1000 0000 uuuu uuuu canstat_ro pic18f2xk80 pic18f4xk80 pic18f6xk80 1000 0000 1000 0000 uuuu uuuu b0d7 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b0d6 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b0d5 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b0d4 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b0d3 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu table 5-4: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 5-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
? 2011 microchip technology inc. ds39977d-page 101 pic18f66k80 family b0d2 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b0d1 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b0d0 pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b0dlc pic18f2xk80 pic18f4xk80 pic18f6xk80 -xxx xxxx -uuu uuuu -uuu uuuu b0eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b0eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b0sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx x-xx uuuu u-uu uuuu uuuu b0sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu b0con pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu txbie pic18f2xk80 pic18f4xk80 pic18f6xk80 ---0 00-- ---u uu-- ---u uu-- bie0 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu bsel0 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 00-- 0000 00-- uuuu uu-- msel3 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu msel2 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu msel1 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu msel0 pic18f2xk80 pic18f4xk80 pic18f6xk80 0101 0000 0101 0000 uuuu uuuu rxfbcon7 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu rxfbcon6 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu rxfbcon5 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu rxfbcon4 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu rxfbcon3 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu rxfbcon2 pic18f2xk80 pic18f4xk80 pic18f6xk80 0001 0001 0001 0001 uuuu uuuu rxfbcon1 pic18f2xk80 pic18f4xk80 pic18f6xk80 0001 0001 0001 0001 uuuu uuuu rxfbcon0 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu sdflc pic18f2xk80 pic18f4xk80 pic18f6xk80 ---0 0000 ---0 0000 ---u uuuu rxf15eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf15eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf15sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- x-xx uuu- u-uu uuu- u-uu rxf15sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf14eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf14eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf14sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- x-xx uuu- u-uu uuu- u-uu rxf14sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf13eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu table 5-4: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 5-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
pic18f66k80 family ds39977d-page 102 ? 2011 microchip technology inc. rxf13eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf13sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- x-xx uuu- u-uu uuu- u-uu rxf13sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf12eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf12eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf12sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- x-xx uuu- u-uu uuu- u-uu rxf12sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf11eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf11eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf11sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- x-xx uuu- u-uu uuu- u-uu rxf11sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf10eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf10eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf10sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- x-xx uuu- u-uu uuu- u-uu rxf10sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- x-xx uuu- u-uu uuu- u-uu rxf9eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf9eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf9sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- x-xx uuu- u-uu uuu- u-uu rxf9sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf8eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf8eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf8sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- x-xx uuu- u-uu uuu- u-uu rxf8sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf7eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf7eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf7sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- x-xx uuu- u-uu uuu- u-uu rxf7sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf6eidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf6eidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxf6sidl pic18f2xk80 pic18f4xk80 pic18f6xk80 xxx- x-xx uuu- u-uu uuu- u-uu rxf6sidh pic18f2xk80 pic18f4xk80 pic18f6xk80 xxxx xxxx uuuu uuuu uuuu uuuu rxfcon0 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu rxfcon1 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu brgcon3 pic18f2xk80 pic18f4xk80 pic18f6xk80 00-- -000 00-- -000 ? table 5-4: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 5-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
? 2011 microchip technology inc. ds39977d-page 103 pic18f66k80 family brgcon2 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu brgcon1 pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu txerrcnt pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu rxerrcnt pic18f2xk80 pic18f4xk80 pic18f6xk80 0000 0000 0000 0000 uuuu uuuu table 5-4: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition. shaded cells indicate conditions do not apply for the designated device. note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 5-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled, depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: this register reads all ? 0 ?s until the ecan? technology is set up in mode 1 or mode 2.
pic18f66k80 family ds39977d-page 104 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds39977d-page 105 pic18f66k80 family 6.0 memory organization pic18f66k80 family devices have these types of memory: ? program memory ? data ram ? data eeprom as harvard architecture devices, the data and program memories use separate busses. this enables concurrent access of the two memory spaces. the data eeprom, for practical purposes, can be regarded as a peripheral device because it is addressed and accessed through a set of control registers. additional detailed information on the operation of the flash program memory is provided in section 7.0 ?flash program memory? . the data eeprom is discussed separately in section 8.0 ?data eeprom memory? . figure 6-1: memory maps for pic18f66k80 family devices note: sizes of memory areas are not to scale. sizes of program memory areas are enhanced to show detail. unimplemented read as ? 0 ? 000000h 1fffffh 00ffffh pc<20:0> stack level 1 ? stack level 31 ? ? call, callw, rcall, return, retfie, retlw, 21 user memory space on-chip memory addulnk, subulnk pic18fx6k80 unimplemented read as ? 0 ? on-chip memory pic18fx5k80 007fffh
pic18f66k80 family ds39977d-page 106 ? 2011 microchip technology inc. 6.1 program memory organization pic18 microcontrollers implement a 21-bit program counter that is capable of addressing a 2-mbyte program memory space. accessing a location between the upper boundary of the physically implemented memory and the 2-mbyte address will return all ? 0 ?s (a nop instruction). the entire pic18f66k80 family offers a range of on-chip flash program memory sizes, from 32 kbytes (16,384 single-word instructions) to 64 kbytes (32,768 single-word instructions). ? pic18f25k80, pic18f45k80 and pic18f65k80 ? 32 kbytes of flash memory, storing up to 16,384 single-word instructions ? pic18f26k80, pic18f46k80 and pic18f66k80 ? 64 kbytes of flash memory, storing up to 32,768 single-word instructions the program memory maps for individual family members are shown in figure 6-1 . 6.1.1 hard memory vectors all pic18 devices have a total of three hard-coded return vectors in their program memory space. the reset vector address is the default value to which the program counter returns on all device resets. it is located at 0000h. pic18 devices also have two interrupt vector addresses for handling high-priority and low-priority interrupts. the high-priority interrupt vector is located at 0008h and the low-priority interrupt vector is at 0018h. the locations of these vectors are shown, in relation to the program memory map, in figure 6-2 . figure 6-2: hard vector for pic18f66k80 family devices reset vector low-priority interrupt vector 0000h 0018h on-chip program memory high-priority interrupt vector 0008h 1fffffh read ? 0 ? legend: (top of memory) represents upper boundary of on-chip program memory space (see figure 6-1 for device-specific values). shaded area represents unimplemented memory. areas are not shown to scale.
? 2011 microchip technology inc. ds39977d-page 107 pic18f66k80 family 6.1.2 program counter the program counter (pc) specifies the address of the instruction to fetch for execution. the pc is 21 bits wide and contained in three separate 8-bit registers. the low byte, known as the pcl register, is both readable and writable. the high byte, or pch register, contains the pc<15:8> bits and is not directly readable or writable. updates to the pch register are performed through the pclath register. the upper byte is called pcu. this register contains the pc<20:16> bits; it is also not directly readable or writable. updates to the pcu register are performed through the pclatu register. the contents of pclath and pclatu are transferred to the program counter by any operation that writes pcl. similarly, the upper two bytes of the program counter are transferred to pclath and pclatu by an operation that reads pcl. this is useful for computed offsets to the pc (see section 6.1.5.1 ?computed goto ? ). the pc addresses bytes in the program memory. to prevent the pc from becoming misaligned with word instructions, the least significant bit (lsb) of pcl is fixed to a value of ? 0 ?. the pc increments by two to address sequential instructions in the program memory. the call , rcall , goto and program branch instructions write to the program counter directly. for these instructions, the contents of pclath and pclatu are not transferred to the program counter. 6.1.3 return address stack the return address stack enables execution of any combination of up to 31 program calls and interrupts. the pc is pushed onto the stack when a call or rcall instruction is executed or an interrupt is acknowledged. the pc value is pulled off the stack on a return , retlw or a retfie instruction. the value is also pulled off the stack on addulnk and subulnk instructions if the extended instruction set is enabled. pclatu and pclath are not affected by any of the return or call instructions. the stack operates as a 31-word by 21-bit ram and a 5-bit stack pointer, stkptr. the stack space is not part of either program or data space. the stack pointer is readable and writable and the address on the top of the stack is readable and writable through the top-of-stack (tos) special function registers. data can also be pushed to, or popped from the stack, using these registers. a call type instruction causes a push onto the stack. the stack pointer is first incremented and the location pointed to by the stack pointer is written with the contents of the pc (already pointing to the instruction following the call ). a return type instruction causes a pop from the stack. the contents of the location pointed to by the stkptr are transferred to the pc and then the stack pointer is decremented. the stack pointer is initialized to ? 00000 ? after all resets. there is no ram associated with the location corresponding to a stack pointer value of ? 00000 ?; this is only a reset value. status bits indicate if the stack is full, has overflowed or has underflowed. 6.1.3.1 top-of-stack access only the top of the return address stack is readable and writable. a set of three registers, tosu:tosh:tosl, holds the contents of the stack location pointed to by the stkptr register ( figure 6-3 ). this allows users to implement a software stack, if necessary. after a call , rcall or interrupt (or addulnk and subulnk instruc- tions, if the extended instruction set is enabled), the software can read the pushed value by reading the tosu:tosh:tosl registers. these values can be placed on a user-defined software stack. at return time, the software can return these values to tosu:tosh:tosl and do a return. while accessing the stack, users must disable the global interrupt enable bits to prevent inadvertent stack corruption. figure 6-3: return address stack and associated registers 00011 001a34h 11111 11110 11101 00010 00001 00000 00010 return address stack<20:0> top-of-stack 000d58h tosl tosh tosu 34h 1ah 00h stkptr<4:0> top-of-stack registers stack pointer
pic18f66k80 family ds39977d-page 108 ? 2011 microchip technology inc. 6.1.3.2 return stack pointer (stkptr) the stkptr register ( register 6-1 ) contains the stack pointer value, the stkful (stack full) status bit and the stkunf (stack underflow) status bits. the value of the stack pointer can be 0 through 31. the stack pointer increments before values are pushed onto the stack and decrements after values are popped off of the stack. on reset, the stack pointer value will be zero. the user may read and write the stack pointer value. this feature can be used by a real-time operating system (rtos) for return stack maintenance. after the pc is pushed onto the stack 31 times (without popping any values off the stack), the stkful bit is set. the stkful bit is cleared by software or by a por. what happens when the stack becomes full depends on the state of the stvren (stack overflow reset enable) configuration bit. (for a description of the device configuration bits, see section 28.1 ?configu- ration bits? .) if stvren is set (default), the 31st push will push the (pc + 2) value onto the stack, set the stkful bit and reset the device. the stkful bit will remain set and the stack pointer will be set to zero. if stvren is cleared, the stkful bit will be set on the 31st push and the stack pointer will increment to 31. any additional pushes will not overwrite the 31st push and the stkptr will remain at 31. when the stack has been popped enough times to unload the stack, the next pop will return a value of zero to the pc and set the stkunf bit, while the stack pointer remains at zero. the stkunf bit will remain set until cleared by software or until a por occurs. 6.1.3.3 push and pop instructions since the top-of-stack is readable and writable, the ability to push values onto the stack and pull values off of the stack, without disturbing normal program execu- tion, is a desirable feature. the pic18 instruction set includes two instructions, push and pop , that permit the tos to be manipulated under software control. tosu, tosh and tosl can be modified to place data or a return address on the stack. the push instruction places the current pc value onto the stack. this increments the stack pointer and loads the current pc value onto the stack. the pop instruction discards the current tos by decrementing the stack pointer. the previous value pushed onto the stack then becomes the tos value. note: returning a value of zero to the pc on an underflow has the effect of vectoring the program to the reset vector, where the stack conditions can be verified and appropriate actions can be taken. this is not the same as a reset, as the contents of the sfrs are not affected. register 6-1: stkptr: stack pointer register r/c-0 r/c-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 stkful (1) stkunf (1) ? sp4 sp3 sp2 sp1 sp0 bit 7 bit 0 legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 stkful: stack full flag bit (1) 1 = stack has become full or overflowed 0 = stack has not become full or overflowed bit 6 stkunf: stack underflow flag bit (1) 1 = stack underflow occurred 0 = stack underflow did not occur bit 5 unimplemented: read as ? 0 ? bit 4-0 sp<4:0>: stack pointer location bits note 1: bit 7 and bit 6 are cleared by user software or by a por.
? 2011 microchip technology inc. ds39977d-page 109 pic18f66k80 family 6.1.3.4 stack full and underflow resets device resets on stack overflow and stack underflow conditions are enabled by setting the stvren bit (config4l<0>). when stvren is set, a full or under- flow condition will set the appropriate stkful or stkunf bit and then cause a device reset. when stvren is cleared, a full or underflow condition will set the appropriate stkful or stkunf bit, but not cause a device reset. the stkful or stkunf bits are cleared by the user software or a power-on reset. 6.1.4 fast register stack a fast register stack is provided for the status, wreg and bsr registers to provide a ?fast return? option for interrupts. this stack is only one level deep and is neither readable nor writable. it is loaded with the current value of the corresponding register when the processor vectors for an interrupt. all interrupt sources will push values into the stack registers. the values in the registers are then loaded back into the working registers if the retfie , fast instruction is used to return from the interrupt. if both low and high-priority interrupts are enabled, the stack registers cannot be used reliably to return from low-priority interrupts. if a high-priority interrupt occurs while servicing a low-priority interrupt, the stack register values stored by the low-priority interrupt will be overwritten. in these cases, users must save the key registers in software during a low-priority interrupt. if interrupt priority is not used, all interrupts may use the fast register stack for returns from interrupt. if no interrupts are used, the fast register stack can be used to restore the status, wreg and bsr registers at the end of a subroutine call. to use the fast register stack for a subroutine call, a call label , fast instruction must be executed to save the status, wreg and bsr registers to the fast register stack. a return , fast instruction is then executed to restore these registers from the fast register stack. example 6-1 shows a source code example that uses the fast register stack during a subroutine call and return. example 6-1: fast register stack code example 6.1.5 look-up tables in program memory there may be programming situations that require the creation of data structures, or look-up tables, in program memory. for pic18 devices, look-up tables can be implemented in two ways: ? computed goto ? table reads 6.1.5.1 computed goto a computed goto is accomplished by adding an offset to the program counter. an example is shown in example 6-2 . a look-up table can be formed with an addwf pcl instruction and a group of retlw nn instructions. the w register is loaded with an offset into the table before executing a call to that table. the first instruction of the called routine is the addwf pcl instruction. the next instruction executed will be one of the retlw nn instructions that returns the value, ? nn ?, to the calling function. the offset value (in wreg) specifies the number of bytes that the program counter should advance and should be multiples of two (lsb = 0 ). in this method, only one data byte may be stored in each instruction location and room on the return address stack is required. example 6-2: computed goto using an offset value 6.1.5.2 table reads a better method of storing data in program memory allows two bytes of data to be stored in each instruction location. look-up table data may be stored two bytes per program word while programming. the table pointer (tblptr) specifies the byte address and the table latch (tablat) contains the data that is read from the program memory. data is transferred from program memory one byte at a time. the table read operation is discussed further in section 7.1 ?table reads and table writes? . call sub1, fast ;status, wreg, bsr ;saved in fast register ;stack ? ? sub1 ? ? return fast ;restore values saved ;in fast register stack movf offset, w call table org nn00h table addwf pcl retlw nnh retlw nnh retlw nnh . . .
pic18f66k80 family ds39977d-page 110 ? 2011 microchip technology inc. 6.2 pic18 instruction cycle 6.2.1 clocking scheme the microcontroller clock input, whether from an internal or external source, is internally divided by four to generate four non-overlapping quadrature clocks (q1, q2, q3 and q4). internally, the program counter is incremented on every q1, with the instruction fetched from the program memory and latched into the instruction register (ir) during q4. the instruction is decoded and executed during the following q1 through q4. the clocks and instruction execution flow are shown in figure 6-4 . 6.2.2 instruction flow/pipelining an ?instruction cycle? consists of four q cycles, q1 through q4. the instruction fetch and execute are pipe- lined in such a manner that a fetch takes one instruction cycle, while the decode and execute take another instruction cycle. however, due to the pipelining, each instruction effectively executes in one cycle. if an instruction (such as goto ) causes the program counter to change, two cycles are required to complete the instruction. (see example 6-3 .) a fetch cycle begins with the program counter (pc) incrementing in q1. in the execution cycle, the fetched instruction is latched into the instruction register (ir) in cycle, q1. this instruction is then decoded and executed during the q2, q3 and q4 cycles. data memory is read during q2 (operand read) and written during q4 (destination write). figure 6-4: clock/instruction cycle example 6-3: instruction pipeline flow q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 q1 q2 q3 q4 pc osc2/clko (rc mode) pc pc + 2 pc + 4 fetch inst (pc) execute inst (pc ? 2) fetch inst (pc + 2) execute inst (pc) fetch inst (pc + 4) execute inst (pc + 2) internal phase clock all instructions are single cycle, except for any program branches. these take two cycles since the fetch instruction is ?flushed? from the pipeline while the new instruction is being fetched and then executed. t cy 0t cy 1t cy 2t cy 3t cy 4t cy 5 1. movlw 55h fetch 1 execute 1 2. movwf portb fetch 2 execute 2 3. bra sub_1 fetch 3 execute 3 4. bsf porta, bit3 (forced nop) fetch 4 flush ( nop ) 5. instruction @ address sub_1 fetch sub_1 execute sub_1
? 2011 microchip technology inc. ds39977d-page 111 pic18f66k80 family 6.2.3 instructions in program memory the program memory is addressed in bytes. instruc- tions are stored as two or four bytes in program memory. the least significant byte (lsb) of an instruction word is always stored in a program memory location with an even address (lsb = 0 ). to maintain alignment with instruction boundaries, the pc incre- ments in steps of two and the lsb will always read ? 0 ? (see section 6.1.2 ?program counter? ). figure 6-5 shows an example of how instruction words are stored in the program memory. the call and goto instructions have the absolute program memory address embedded into the instruc- tion. since instructions are always stored on word boundaries, the data contained in the instruction is a word address. the word address is written to pc<20:1> which accesses the desired byte address in program memory. instruction #2 in figure 6-5 shows how the instruction, goto 0006h , is encoded in the program memory. program branch instructions, which encode a relative address offset, operate in the same manner. the offset value stored in a branch instruction represents the number of single-word instructions that the pc will be offset by. for more details on the instruction set, see section 29.0 ?instruction set summary? . figure 6-5: instructions in program memory 6.2.4 two-word instructions the standard pic18 instruction set has four, two-word instructions: call , movff , goto and lsfr . in all cases, the second word of the instructions always has ? 1111 ? as its four most significant bits (msbs). the other 12 bits are literal data, usually a data memory address. the use of ? 1111 ? in the 4 msbs of an instruction specifies a special form of nop . if the instruction is executed in proper sequence, immediately after the first word, the data in the second word is accessed and used by the instruction sequence. if the first word is skipped for some reason and the second word is executed by itself, a nop is executed instead. this is necessary for cases when the two-word instruction is preceded by a conditional instruction that changes the pc. example 6-4 shows how this works. example 6-4: two-word instructions word address lsb = 1 lsb = 0 ? program memory byte locations ? ? 000000h 000002h 000004h 000006h instruction 1: movlw 055h 0fh 55h 000008h instruction 2: goto 0006h efh 03h 00000ah f0h 00h 00000ch instruction 3: movff 123h, 456h c1h 23h 00000eh f4h 56h 000010h 000012h 000014h note: for information on two-word instructions in the extended instruction set, see section 6.5 ?program memory and the extended instruction set? . case 1: object code source code 0110 0110 0000 0000 tstfsz reg1 ; is ram location 0? 1100 0001 0010 0011 movff reg1, reg2 ; no, skip this word 1111 0100 0101 0110 ; execute this word as a nop 0010 0100 0000 0000 addwf reg3 ; continue code case 2: object code source code 0110 0110 0000 0000 tstfsz reg1 ; is ram location 0? 1100 0001 0010 0011 movff reg1, reg2 ; yes, execute this word 1111 0100 0101 0110 ; 2nd word of instruction 0010 0100 0000 0000 addwf reg3 ; continue code
pic18f66k80 family ds39977d-page 112 ? 2011 microchip technology inc. 6.3 data memory organization the data memory in pic18 devices is implemented as static ram. each register in the data memory has a 12-bit address, allowing up to 4,096 bytes of data memory. the memory space is divided into 16 banks that contain 256 bytes each. figure 6-6 and figure 6-7 show the data memory organization for the devices. the data memory contains special function registers (sfrs) and general purpose registers (gprs). the sfrs are used for control and status of the controller and peripheral functions, while gprs are used for data storage and scratchpad operations in the user?s application. any read of an unimplemented location will read as ? 0 ?s. the instruction set and architecture allow operations across all banks. the entire data memory may be accessed by direct, indirect or indexed addressing modes. addressing modes are discussed later in this section. to ensure that commonly used registers (select sfrs and select gprs) can be accessed in a single cycle, pic18 devices implement an access bank. this is a 256-byte memory space that provides fast access to select sfrs and the lower portion of gpr bank 0 with- out using the bank select register. for details on the access ram, see section 6.3.2 ?access bank? . 6.3.1 bank select register large areas of data memory require an efficient addressing scheme to make rapid access to any address possible. ideally, this means that an entire address does not need to be provided for each read or write operation. for pic18 devices, this is accom- plished with a ram banking scheme. this divides the memory space into 16 contiguous banks of 256 bytes. depending on the instruction, each location can be addressed directly by its full 12-bit address, or an eight-bit, low-order address and a four-bit bank pointer. most instructions in the pic18 instruction set make use of the bank pointer, known as the bank select register (bsr). this sfr holds the four most significant bits of a location?s address. the instruction itself includes the eight least significant bits. only the four lower bits of the bsr are implemented (bsr<3:0>). the upper four bits are unused and always read as ? 0 ?, and cannot be written to. the bsr can be loaded directly by using the movlb instruction. the value of the bsr indicates the bank in data memory. the eight bits in the instruction show the loca- tion in the bank and can be thought of as an offset from the bank?s lower boundary. the relationship between the bsr?s value and the bank division in data memory is shown in figure 6-7 . since up to 16 registers may share the same low-order address, the user must always be careful to ensure that the proper bank is selected before performing a data read or write. for example, writing what should be program data to an eight-bit address of f9h while the bsr is 0fh, will end up resetting the program counter. while any bank can be selected, only those banks that are actually implemented can be read or written to. writes to unimplemented banks are ignored, while reads from unimplemented banks will return ? 0 ?s. even so, the status register will still be affected as if the operation was successful. the data memory map in figure 6-6 indicates which banks are implemented. in the core pic18 instruction set, only the movff instruction fully specifies the 12-bit address of the source and target registers. when this instruction executes, it ignores the bsr completely. all other instructions include only the low-order address as an operand and must use either the bsr or the access bank to locate their target registers. note: the operation of some aspects of data memory are changed when the pic18 extended instruction set is enabled. see section 6.6 ?data memory and the extended instruction set? for more information.
? 2011 microchip technology inc. ds39977d-page 113 pic18f66k80 family figure 6-6: data memory map for pic18fx5k80 and pic18fx6k80 devices 00h 5fh 60h ffh access bank when a = 0 : the bsr is ignored and the access bank is used. the first 96 bytes are general purpose ram (from bank 0). the second 160 bytes are special function registers (from bank 15). when a = 1 : the bsr specifies the bank used by the instruction. access ram high access ram low (sfrs) bank 0 bank 1 bank 14 bank 15 data memory map bsr<3:0> = 0000 = 0001 = 1111 060h 05fh 1ffh 100h 0ffh 000h access ram ffh 00h ffh 00h ffh 00h gpr gpr sfr bank 2 = 0010 2ffh 200h bank 3 ffh 00h gpr ffh = 0011 gpr gpr gpr gpr gpr 4ffh 400h 5ffh 500h 3ffh 300h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h 00h = 0110 = 0111 = 0101 = 0100 bank 4 bank 5 bank 6 bank 7 bank 8 = 1110 6ffh 600h 7ffh 700h 800h bank 9 bank 10 bank 11 bank 12 bank 13 8ffh 900h 9ffh a00h affh b00h bffh c00h cffh d00h dffh e00h effh ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h gpr (1) gpr gpr gpr gpr gpr gpr = 1000 = 1001 = 1010 = 1011 = 1100 = 1101 f00h f5fh f60h fffh gpr (1) ffh 00h note 1: addresses, e41h through f5fh, are also used by sfrs, but are not part of the access ram. users must always use the complete address, or load the proper bsr value, to access these registers.
pic18f66k80 family ds39977d-page 114 ? 2011 microchip technology inc. figure 6-7: use of the bank select register (direct addressing) 6.3.2 access bank while the use of the bsr, with an embedded 8-bit address, allows users to address the entire range of data memory, it also means that the user must ensure that the correct bank is selected. if not, data may be read from, or written to, the wrong location. this can be disastrous if a gpr is the intended target of an operation, but an sfr is written to instead. verifying and/or changing the bsr for each read or write to data memory can become very inefficient. to streamline access for the most commonly used data memory locations, the data memory is configured with an access bank, which allows users to access a mapped block of memory without specifying a bsr. the access bank consists of the first 96 bytes of memory (00h-5fh) in bank 0 and the last 160 bytes of memory (60h-ffh) in bank 15. the lower half is known as the ?access ram? and is composed of gprs. the upper half is where the device?s sfrs are mapped. these two areas are mapped contiguously in the access bank and can be addressed in a linear fashion by an eight-bit address ( figure 6-6 ). the access bank is used by core pic18 instructions that include the access ram bit (the ?a? parameter in the instruction). when ?a? is equal to ? 1 ?, the instruction uses the bsr and the 8-bit address included in the opcode for the data memory address. when ?a? is ? 0 ?, however, the instruction is forced to use the access bank address map. in that case, the current value of the bsr is ignored entirely. using this ?forced? addressing allows the instruction to operate on a data address in a single cycle without updating the bsr first. for 8-bit addresses of 60h and above, this means that users can evaluate and operate on sfrs more efficiently. the access ram below 60h is a good place for data values that the user might need to access rapidly, such as immediate computational results or common program variables. access ram also allows for faster and more code efficient context saving and switching of variables. the mapping of the access bank is slightly different when the extended instruction set is enabled (xinst configuration bit = 1 ). this is discussed in more detail in section 6.6.3 ?mapping the access bank in indexed literal offset mode? . 6.3.3 general purpose register file pic18 devices may have banked memory in the gpr area. this is data ram which is available for use by all instructions. gprs start at the bottom of bank 0 (address 000h) and grow upwards towards the bottom of the sfr area. gprs are not initialized by a power-on reset and are unchanged on all other resets. note 1: the access ram bit of the instruction can be used to force an override of the selected bank (bsr<3:0>) to the registers of the access bank. 2: the movff instruction embeds the entire 12-bit address in the instruction. data memory bank select (2) 7 0 from opcode (2) 0000 000h 100h 200h 300h f00h e00h fffh bank 0 bank 1 bank 2 bank 14 bank 15 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh 00h ffh bank 3 through bank 13 0010 11111111 7 0 bsr (1) 11111111
? 2011 microchip technology inc. ds39977d-page 115 pic18f66k80 family 6.3.4 special function registers the special function registers (sfrs) are registers used by the cpu and peripheral modules for controlling the desired operation of the device. these registers are implemented as static ram. sfrs start at the top of data memory (fffh) and extend downward to occupy all of bank 15 (f00h to fffh) and the top part of bank 14 (ef4h to effh). a list of these registers is given in tab l e 6 - 1 and table 6-2 . the sfrs can be classified into two sets: those associated with the ?core? device functionality (alu, resets and interrupts) and those related to the peripheral functions. the reset and interrupt registers are described in their respective chapters, while the alu?s status register is described later in this section. registers related to the operation of the peripheral features are described in t he chapter for that peripheral. the sfrs are typically distributed among the peripherals whose functions they control. unused sfr locations are unimplemented and read as ? 0 ?s. table 6-1: special function register map for pic18f66k80 family addr. name addr. name addr. name addr. name addr. name addr. name fffh tosu fdfh indf2 (1) fbfh eccp1as f9fh ipr1 f7fh eecon1 f5fh cm1con (5) ffeh tosh fdeh postinc2 (1) fbeh eccp1del f9eh pir1 f7eh eecon2 f5eh cm2con (5) ffdh tosl fddh postdec2 (1) fbdh ccpr1h f9dh pie1 f7dh spbrgh1 f5dh ancon0 (5) ffch stkptr fdch preinc2 (1) fbch ccpr1l f9ch pstr1con f7ch spbrgh2 f5ch ancon1 (5) ffbh pclatu fdbh plusw2 (1) fbbh ccp1con f9bh osctune f7bh spbrg2 f5bh wpub (5) ffah pclath fdah fsr2h fbah txsta2 f9ah refocon f7ah rcreg2 f5ah iocb (5) ff9h pcl fd9h fsr2l fb9h baudcon2 f99h ccptmrs f79h txreg2 f59h pmd0 (5) ff8h tblptru fd8h status fb8h ipr4 f98h trisg (3) f78h ipr5 f58h pmd1 (5) ff7h tblptrh fd7h tmr0h fb7h pir4 f97h trisf (3) f77h pir5 f57h pmd2 (5) ff6h tblptrl fd6h tmr0l fb6h pie4 f96h trise (4) f76h pie5 f56h padcfg1 (5) ff5h tablat fd5h t0con fb5h cvrcon f95h trisd (4) f75h eeadrh f55h ctmuconh (5) ff4h prodh fd4h ? (2) fb4h cmstat f94h trisc f74h eeadr f54h ctmuconl (5) ff3h prodl fd3h osccon fb3h tmr3h f93h trisb f73h eedata f53 h ctmuiconh (5) ff2h intcon fd2h osccon2 fb2h tmr3l f92h trisa f72h ecancon f52 h ccpr2h (5) ff1h intcon2 fd1h wdtcon fb1h t3con f91h odcon f71h comstat f51 h ccpr2l (5) ff0h intcon3 fd0h rcon fb0h t3gcon f90h slrcon f70h ciocon f50 h ccp2con (4,5) fefh indf0 (1) fcfh tmr1h fafh spbrg1 f8fh latg (3) f6fh cancon f4f h ccpr3h (4,5) feeh postinc0 (1) fceh tmr1l faeh rcreg1 f8eh latf (3) f6eh canstat f4e h ccpr3l (4,5) fedh postdec0 (1) fcdh t1con fadh txreg1 f8dh late (4) f6dh rxb0d7 f4d h ccp3con (5) fech preinc0 (1) fcch tmr2 fach txsta1 f8ch latd (4) f6ch rxb0d6 f4c h ccpr4h (5) febh plusw0 (1) fcbh pr2 fabh rcsta1 f8bh latc f6bh rxb0d5 f4b h ccpr4l (5) feah fsr0h fcah t2con faah t1gcon f8ah latb f6ah rxb0d4 f4a h ccp4con (5) fe9h fsr0l fc9h sspbuf fa9h pr4 f89h lata f69h rxb0d3 f49 h ccpr5h (5) fe8h wreg fc8h sspadd fa8h hlvdcon f88h t4con f68h rxb0d2 f48 h ccpr5l (5) fe7h indf1 (1) fc8h sspmsk fa7h baudcon1 f87h tmr4 f67h rxb0d1 f47 h ccp5con (5) fe6h postinc1 (1) fc7h sspstat fa6h rcsta2 f86h portg (3) f66h rxb0d0 f46 h pspcon (4,5) fe5h postdec1 (1) fc6h sspcon1 fa5h ipr3 f85h portf (3) f65h rxb0dlc f45 h mdcon (3,5) fe4h preinc1 (1) fc5h sspcon2 fa4h pir3 f84h porte f64h rxb0eidl f44 h mdsrc (3,5) fe3h plusw1 (1) fc4h adresh fa3h pie3 f83h portd (4) f63h rxb0eidh f43 h mdcarh (3,5) fe2h fsr1h fc3h adresl fa2h ipr2 f82h portc f62h rxb0sidl f42 h mdcarl (3,5) fe1h fsr1l fc2h adcon0 fa1h pir2 f81h portb f61h rxb0sidh f41 h ? (2) fe0h bsr fc1h adcon1 fa0h pie2 f80h porta f60h rxb0con f40 h ? (2) fc0h adcon2 note 1: this is not a physical register. 2: unimplemented registers are read as ? 0 ?. 3: this register is only available on devices with 64 pins. 4: this register is not available on devices with 28-pins. 5: addresses, e41h through f5fh, are also used by the sfrs, but are not part of the access ram. to access these registers, users m ust always load the proper bsr value.
pic18f66k80 family ds39977d-page 116 ? 2011 microchip technology inc. f3fh cancon_ro0 (5) f0fh cancon_ro3 (5) edfh cancon_ro4 (5) eafh cancon_ro7 (5) e7fh txbie (5) e4fh rxf7eidl (5) f3eh canstat_ro0 (5) f0eh canstat_ro3 (5) edeh canstat_ro4 (5) eaeh canstat_ro7 (5) e7eh bie0 (5) e4eh rxf7eidh (5) f3dh rxb1d7 (5) f0dh txb2d7 (5) eddh b5d7 (5) eadh b2d7 (5) e7dh bsel0 (5) e4dh rxf7sidl (5) f3ch rxb1d6 (5) f0ch txb2d6 (5) edch b5d6 (5) each b2d6 (5) e7ch msel3 (5) e4ch rxf7sidh (5) f3bh rxb1d5 (5) f0bh txb2d5 (5) edbh b5d5 (5) eabh b2d5 (5) e7bh msel2 (5) e4bh rxf6eidl (5) f3ah rxb1d4 (5) f0ah txb2d4 (5) edah b5d4 (5) eaah b2d4 (5) e7ah msel1 (5) e4ah rxf6eidh (5) f39h rxb1d3 (5) f09h txb2d3 (5) ed9h b5d3 (5) ea9h b2d3 (5) e79h msel0 (5) e49h rxf6sidl (5) f38h rxb1d2 (5) f08h txb2d2 (5) ed8h b5d2 (5) ea8h b2d2 (5) e78h rxfbcon7 (5) e48h rxf6sidh (5) f37h rxb1d1 (5) f07h txb2d1 (5) ed7h b5d1 (5) ea7h b2d1 (5) e77h rxfbcon6 (5) e47h rxfcon0 (5) f36h rxb1d0 (5) f06h txb2d0 (5) ed6h b5d0 (5) ea6h b2d0 (5) e76h rxfbcon5 (5) e46h rxfcon1 (5) f35h rxb1dlc (5) f05h txb2dlc (5) ed5h b5dlc (5) ea5h b2dlc (5) e75h rxfbcon4 (5) e45h brgcon3 (5) f34h rxb1eidl (5) f04h txb2eidl (5) ed4h b5eidl (5) ea4h b2eidl (5) e74h rxfbcon3 (5) e44h brgcon2 (5) f33h rxb1eidh (5) f03h txb2eidh (5) ed3h b5eidh (5) ea3h b2eidh (5) e73h rxfbcon2 (5) e43h brgcon1 (5) f32h rxb1sidl (5) f02h txb2sidl (5) ed2h b5sidl (5) ea2h b2sidl (5) e72h rxfbcon1 (5) e42h txerrcnt (5) f31h rxb1sidh (5) f01h txb2sidh (5) ed1h b5sidh (5) ea1h b2sidh (5) e71h rxfbcon0 (5) e41h rxerrcnt (5) f30h rxb1con (5) f00h txb2con (5) ed0h b5con (5) ea0h b2con (5) e70h sdflc (5) f30h rxb1con (5) effh rxm1eidl (5) ecfh cancon_ro5 (5) e9fh cancon_ro8 (5) e6fh rxf15eidl (5) f2fh cancon_ro1 (5) efeh rxm1eidh (5) eceh canstat_ro5 (5) e9eh canstat_ro8 (5) e6eh rxf15eidh (5) f2eh canstat_ro1 (5) efdh rxm1sidl (5) ecdh b4d7 (5) e9dh b1d7 (5) e6dh rxf15sidl (5) f2dh txb0d7 (5) efch rxm1sidh (5) ecch b4d6 (5) e9ch b1d6 (5) e6ch rxf15sidh (5) f2ch txb0d6 (5) efbh rxm0eidl (5) ecbh b4d5 (5) e9bh b1d5 (5) e6bh rxf14eidl (5) f2bh txb0d5 (5) efah rxm0eidh (5) ecah b4d4 (5) e9ah b1d4 (5) e6ah rxf14eidh (5) f2ah txb0d4 (5) ef9h rxm0sidl (5) ec9h b4d3 (5) e99h b1d3 (5) e69h rxf14sidl (5) f29h txb0d3 (5) ef8h rxm0sidh (5) ec8h b4d2 (5) e98h b1d2 (5) e68h rxf14sidh (5) f28h txb0d2 (5) ef7h rxf5eidl (5) ec7h b4d1 (5) e97h b1d1 (5) e67h rxf13eidl (5) f27h txb0d1 (5) ef6h rxf5eidh (5) ec6h b4d0 (5) e96h b1d0 (5) e66h rxf13eidh (5) f26h txb0d0 (5) ef5h rxf5sidl (5) ec5h b4dlc (5) e95h b1dlc (5) e65h rxf13sidl (5) f25h txb0dlc (5) ef4h rxf5sidh (5) ec4h b4eidl (5) e94h b1eidl (5) e64h rxf13sidh (5) f24h txb0eidl (5) ef3h rxf4eidl (5) ec3h b4eidh (5) e93h b1eidh (5) e63h rxf12eidl (5) f23h txb0eidh (5) ef2h rxf4eidh (5) ec2h b4sidl (5) e92h b1sidl (5) e62h rxf12eidh (5) f22h txb0sidl (5) ef1h rxf4sidl (5) ec1h b4sidh (5) e91h b1sidh (5) e61h rxf12sidl (5) f21h txb0sidh (5) ef0h rxf4sidh (5) ec0h b4con (5) e90h b1con (5) e60h rxf12sidh (5) f20h txb0con (5) eefh rxf3eidl (5) ebfh cancon_ro6 (5) e90h b1con (5) e5fh rxf11eidl (5) f1fh cancon_ro2 (5) eeeh rxf3eidh (5) ebeh canstat_ro6 (5) e8fh cancon_ro9 (5) e5eh rxf11eidh (5) f1eh canstat_ro2 (5) eedh rxf3sidl (5) ebdh b3d7 (5) e8eh canstat_ro9 (5) e5dh rxf11sidl (5) f1dh txb1d7 (5) eech rxf3sidh (5) ebch b3d6 (5) e8dh b0d7 (5) e5ch rxf11sidh (5) f1ch txb1d6 (5) eebh rxf2eidl (5) ebbh b3d5 (5) e8ch b0d6 (5) e5bh rxf10eidl (5) f1bh txb1d5 (5) eeah rxf2eidh (5) ebah b3d4 (5) e8bh b0d5 (5) e5ah rxf10eidh (5) f1ah txb1d4 (5) ee9h rxf2sidl (5) eb9h b3d3 (5) e8ah b0d4 (5) e59h rxf10sidl (5) f19h txb1d3 (5) ee8h rxf2sidh (5) eb8h b3d2 (5) e89h b0d3 (5) e58h rxf10sidh (5) f18h txb1d2 (5) ee7h rxf1eidl (5) eb7h b3d1 (5) e88h b0d2 (5) e57h rxf9eidl (5) f17h txb1d1 (5) ee6h rxf1eidh (5) eb6h b3d0 (5) e87h b0d1 (5) e56h rxf9eidh (5) f16h txb1d0 (5) ee5h rxf1sidl (5) eb5h b3dlc (5) e86h b0d0 (5) e55h rxf9sidl (5) f15h txb1dlc (5) ee4h rxf1sidh (5) eb4h b3eidl (5) e85h b0dlc (5) e54h rxf9sidh (5) f14h txb1eidl (5) ee3h rxf0eidl (5) eb3h b3eidh (5) e84h b0eidl (5) e53h rxf8eidl (5) f13h txb1eidh (5) ee2h rxf0eidh (5) eb2h b3sidl (5) e83h b0eidh (5) e52h rxf8eidh (5) f12h txb1sidl (5) ee1h rxf0sidl (5) eb1h b3sidh (5) e82h b0sidl (5) e51h rxf8sidl (5) f11h txb1sidh (5) ee0h rxf0sidh (5) eb0h b3con (5) e81h b0sidh (5) e50h rxf8sidh (5) f10h txb1con (5) e80h b0con (5) table 6-1: special function register map for pic18f66k80 family (continued) addr. name addr. name addr. name addr. name addr. name addr. name note 1: this is not a physical register. 2: unimplemented registers are read as ? 0 ?. 3: this register is only available on devices with 64 pins. 4: this register is not available on devices with 28-pins. 5: addresses, e41h through f5fh, are also used by the sfrs, but are not part of the access ram. to access these registers, users m ust always load the proper bsr value.
? 2011 microchip technology inc. ds39977d-page 117 pic18f66k80 family table 6-2: pic18f66k80 family register file summary addr. file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor on page fffh tosu ? ? ? top-of-stack upper byte (tos<20:16>) 90 ffeh tosh top-of-stack high byte (tos<15:8>) 90 ffdh tosl top-of-stack low byte (tos<7:0>) 90 ffch stkptr stkful stkunf ? sp4 sp3 sp2 sp1 sp0 90 ffbh pclatu ? ? bit 21 holding register for pc<20:16> 90 ffah pclath holding register for pc<15:8> 90 ff9h pcl pc low byte (pc<7:0>) 90 ff8h tblptru ? ? bit 21 program memory table pointer upper byte (tblptr<20:16>) 90 ff7h tblptrh program memory table pointer high byte (tblptr<15:8>) 90 ff6h tblptrl program memory table pointer low byte (tblptr<7:0>) 90 ff5h tablat program memory table latch 90 ff4h prodh product register high byte 90 ff3h prodl product register low byte 90 ff2h intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 90 ff1h intcon2 rbpu intedg0 intedg1 intedg2 intedg3 tmr0ip int3ip rbip 90 ff0h intcon3 int2ip int1ip int3ie int2ie int1ie int3if int2if int1if 90 fefh indf0 uses contents of fsr0 to address data memory ? value of fsr0 not changed (not a physical register) 90 feeh postinc0 uses contents of fsr0 to address data memory ? value of fsr0 post-incremented (not a physical register) 90 fedh postdec0 uses contents of fsr0 to address data memory ? value of fsr0 post-decremented (not a physical register) 90 fech preinc0 uses contents of fsr0 to address data memory ? value of fsr0 pre-incremented (not a physical register) 90 febh plusw0 uses contents of fsr0 to address data memory ? value of fsr0 pre-incremented (not a physical register) ? value of fsr0 offset by w 90 feah fsr0h ? ? ? ? indirect data memory address pointer 0 high byte 90 fe9h fsr0l indirect data memory address pointer 0 low byte 90 fe8h wreg working register 90 fe7h indf1 uses contents of fsr1 to address data memory ? value of fsr1 not changed (not a physical register) 90 fe6h postinc1 uses contents of fsr1 to address data memory ? value of fsr1 post-incremented (not a physical register) 90 fe5h postdec1 uses contents of fsr1 to address data memory ? value of fsr1 post-decremented (not a physical register) 90 fe4h preinc1 uses contents of fsr1 to address data memory ? value of fsr1 pre-incremented (not a physical register) 90 fe3h plusw1 uses contents of fsr1 to address data memory ? value of fsr1 pre-incremented (not a physical register) ? value of fsr1 offset by w 90 fe2h fsr1h ? ? ? ? indirect data memory address pointer 1 high byte 90 fe1h fsr1l indirect data memory address pointer 1 low byte 90 fe0h bsr ? ? ? ? bank select register 90 fdfh indf2 uses contents of fsr2 to address data memory ? value of fsr2 not changed (not a physical register) 90 fdeh postinc2 uses contents of fsr2 to address data memory ? value of fsr2 post-incremented (not a physical register) 91 fddh postdec2 uses contents of fsr2 to address data memory ? value of fsr2 post-decremented (not a physical register) 91 fdch preinc2 uses contents of fsr2 to address data memory ? value of fsr2 pre-incremented (not a physical register) 91 fdbh plusw2 uses contents of fsr2 to address data memory ? value of fsr2 pre-incremented (not a physical register) ? value of fsr2 offset by w 91 fdah fsr2h ? ? ? ? indirect data memory address pointer 2 high byte 91 fd9h fsr2l indirect data memory address pointer 2 low byte 91 fd8h status ? ? ?novzdcc91 fd7h tmr0h timer0 register high byte 91 fd6h tmr0l timer0 register low byte 91 fd5h t0con tmr0on t08bit t0cs t0se psa t0ps2 t0ps1 t0ps0 91 fd4h unimplemented ? fd3h osccon idlen ircf2 ircf1 ircf0 osts hfiofs scs1 scs0 91 fd2h osccon2 ? soscrun ? soscdrv soscgo ? mfiofs mfiosel 91 fd1h wdtcon regslp ?ulplvlsreten ? ulpen ulpsink swdten 91 fd0h rcon ipen sboren cm ri to pd por bor 91
pic18f66k80 family ds39977d-page 118 ? 2011 microchip technology inc. fcfh tmr1h timer1 register high byte 91 fceh tmr1l timer1 register low bytes 91 fcdh t1con tmr1cs1 tmr1cs0 t1ckps1 t1ckps0 soscen t1sync rd16 tmr1on 91 fcch tmr2 timer2 register 91 fcbh pr2 timer2 period register 91 fcah t2con ? t2outps3 t2outps2 t2outps1 t2outps0 tmr2on t2ckps1 t2ckps0 91 fc9h sspbuf mssp receive buffer/transmit register 91 fc8h sspadd mssp address register (i 2 c? slave mode), mssp baud rate reload register (i 2 c master mode) 91 fc8h sspmsk msk7 msk6 msk5 msk4 msk3 msk2 msk1 msk0 91 fc7h sspstat smp cke d/a psr/w ua bf 91 fc6h sspcon1 wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 91 fc5h sspcon2 gcen ackstat ackdt acken rcen pen rsen sen 91 fc4h adresh a/d result register high byte 91 fc3h adresl a/d result register low byte 91 fc2h adcon0 ? chs4 chs3 chs2 chs1 chs0 go/done adon 91 fc1h adcon1 trigsel1 trigsel0 vcfg1 vcfg0 vncfg chsn2 chsn1 chsn0 91 fc0h adcon2 adfm ? acqt2 acqt1 acqt0 adcs2 adcs1 adcs0 91 fbfh eccp1as eccp1ase eccp1as2 eccp1as1 eccp1as0 pss1ac1 pss1ac0 pss1bd1 pss1bd0 91 fbeh eccp1del p1rsen p1dc6 p1dc5 p1dc4 p1dc3 p1dc2 p1dc1 p1dc0 91 fbdh ccpr1h capture/compare/pwm register 1 high byte 91 fbch ccpr1l capture/compare/pwm register 1 low byte 91 fbbh ccp1con p1m1 p1m0 dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 91 fbah txsta2 csrc tx9 txen sync sendb brgh trmt tx9d 92 fb9h baudcon2 abdovf rcidl rxdtp txckp brg16 ? wue abden 92 fb8h ipr4 tmr4ip eeip cmp2ip cmp1ip ? ccp5ip ccp4ip ccp3ip 92 fb7h pir4 tmr4if eeif cmp2if cmp1if ? ccp5if ccp4if ccp3if 92 fb6h pie4 tmr4ie eeie cmp2ie cmp1ie ? ccp5ie ccp4ie ccp3ie 92 fb5h cvrcon cvren cvroe cvrss cvr4 cvr3 cvr2 cvr1 cvr0 92 fb4h cmstat cmp2out cmp1out ? ? ? ? ? ?92 fb3h tmr3h timer3 register high byte 92 fb2h tmr3l timer3 register low bytes 92 fb1h t3con tmr3cs1 tmr3cs0 t3ckps1 t3ckps0 soscen t3sync rd16 tmr3on 92 fb0h t3gcon tmr3ge t3gpol t3gtm t3gspm t3ggo/ t3done t3gval t3gss1 t3gss0 92 fafh spbrg1 eusart1 baud rate generator register low byte 92 faeh rcreg1 eusart1 receive register 92 fadh txreg1 eusart1 transmit register 92 fach txsta1 csrc tx9 txen sync sendb brgh trmt tx9d 92 fabh rcsta1 spen rx9 sren cren adden ferr oerr rx9d 92 faah t1gcon tmr1ge t1gpol t1gtm t1gspm t1ggo/ t1done t1gval t1gss1 t1gss0 92 fa9h pr4 timer4 period register 92 fa8h hlvdcon vdirmag bgvst irvst hlvden hlvdl3 hlvdl2 hlvdl1 hlvdl0 92 fa7h baudcon1 abdovf rcidl rxdtp txckp brg16 ? wue abden 92 fa6h rcsta2 spen rx9 sren cren adden ferr oerr rx9d 92 fa5h ipr3 ? ? rc2ip tx2ip ctmuip ccp2ip ccp1ip ?92 fa4h pir3 ? ? rc2if tx2if ctmuif ccp2if ccp1if ?92 fa3h pie3 ? ? rc2ie tx2ie ctmuie ccp2ie ccp1ie ?92 fa2h ipr2 oscfip ? ? ? bclip hlvdip tmr3ip tmr3gip 92 fa1h pir2 oscfif ? ? ? bclif hlvdif tmr3if tmr3gif 92 fa0h pie2 oscfie ? ? ? bclie hlvdie tmr3ie tmr3gie 92 table 6-2: pic18f66k80 family register file summary (continued) addr. file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor on page
? 2011 microchip technology inc. ds39977d-page 119 pic18f66k80 family f9fh ipr1 pspip adip rc1ip tx1ip sspip tmr1gip tmr2ip tmr1ip 92 f9eh pir1 pspif adif rc1if tx1if sspif tmr1gif tmr2if tmr1if 92 f9dh pie1 pspie adie rc1ie tx1ie sspie tmr1gie tmr2ie tmr1ie 92 f9ch pstr1con cmpl1 cmpl0 ? strsync strd strc strb stra 92 f9bh osctune intsrc pllen tun5 tun4 tun3 tun2 tun1 tun0 93 f9ah refocon roon ? rosslp rosel rodiv3 ro div2 rodiv1 rodiv0 93 f99h ccptmrs ? ? ? c5tsel c4tsel c3tsel c2tsel c1tsel 93 f98h trisg ? ? ? trisg4 trisg3 trisg 2trisg1trisg0 93 f97h trisf trisf7 trisf6 trisf5 tri sf4 trisf3 trisf2 trisf1 trisf0 93 f96h trise trise7 trise6 trise5 trise4 ? trise2 trise1 trise0 93 f95h trisd trisd7 trisd6 trisd5 tri sd4 trisd3 trisd2 trisd1 trisd0 93 f94h trisc trisc7 trisc6 trisc5 tri sc4 trisc3 trisc2 trisc1 trisc0 93 f93h trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 93 f92h trisa trisa7 trisa6 trisa5 ? trisa3 trisa2 trisa1 trisa0 93 f91h odcon sspod ccp5od ccp4od ccp3od ccp2od ccp1od u2od u1od 93 f90h slrcon ? slrg slrf slre slrd slrc slrb slra 93 f8fh latg ? ? ? latg4 latg3 latg2 latg1 latg0 93 f8eh latf latf7 latf6 latf5 latf4 ? latf2 latf1 latf0 93 f8dh late late7 late6 late5 late4 ? late2 late1 late0 93 f8ch latd latd7 latd6 latd5 latd4 latd3 latd2 latd1 latd0 93 f8bh latc latc7 latc6 latc5 latc4 latc3 latc2 latc1 latc0 93 f8ah latb latb7 latb6 latb5 latb4 latb3 latb2 latb1 latb0 93 f89h lata lata7 lata6 lata5 ? lata3 lata2 lata1 lata0 93 f88h t4con ? t4outps3 t4outps2 t4outps1 t4outps0 tmr4on t4ckps1 t4ckps0 93 f87h tmr4 timer4 register 93 f86h portg ? ? ? rg4 rg3 rg2 rg1 rg0 93 f85h portf rf7 rf6 rf5 rf4 rf3 rf2 rf1 rf0 93 f84h porte re7 re6 re5 re4 re3 re2 re1 re0 93 f83h portd rd7 rd6 rd5 rd4 rd3 rd2 rd1 rd0 93 f82h portc rc7 rc6 rc5 rc4 rc3 rc2 rc1 rc0 93 f81h portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 93 f80h porta ra7 ra6 ra5 ? ra3 ra2 ra1 ra0 93 f7fh eecon1 eepgd cfgs ? free wrerr wren wr rd 93 f7eh eecon2 flash self-program control register (not a physical register) 93 f7dh spbrgh1 eusart1 baud rate generator register high byte 93 f7ch spbrgh2 eusart2 baud rate generator register high byte 93 f7bh spbrg2 eusart2 baud rate generator register low byte 93 f7ah rcreg2 eusart2 receive register 93 f79h txreg2 eusart2 transmit register 94 f78h ipr5 irxip wakip errip tx2bip txb1ip txb0ip rxb1ip rxb0ip 94 f77h pir5 irxif wakif errif txb2if txb1if txb0if rxb1if rxb0if 94 f76h pie5 irxie wakie errie tx2bie txb1ie txb0ie rxb1ie rxb0ie 94 f75h eeadrh data ee address register high byte 94 f74h eeadr data ee address register low byte 94 f73h eedata data ee data register 94 f72h ecancon mdsel1 mdsel0 fifowm ewin4 ewin3 ewin2 ewin1 ewin0 94 f71h comstat rxb0ovfl rxb1ovfl txbo txbp rxbp txwarn rxwarn ewarn 94 f70h ciocon tx2src tx2en endrhi cancap ? ? ? clksel 94 f6fh cancon reqop2 reqop1 reqop0 abat win2/fp3 win1/fp2 win0/fp1 fp0 94 f6eh canstat opmode2 opmode1 opmode0 ?/ eicod4 icode2/ eicode3 icode1/ eicode2 icode0/ eicode1 ?/ eicode0 94 table 6-2: pic18f66k80 family register file summary (continued) addr. file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor on page
pic18f66k80 family ds39977d-page 120 ? 2011 microchip technology inc. f6dh rxb0d7 rxb0d77 rxb0d76 rxb0d75 rxb0d74 rxb0d73 rxb0d72 rxb0d71 rxb0d70 94 f6ch rxb0d6 rxb0d67 rxb0d66 rxb0d65 rxb0d64 rxb0d63 rxb0d62 rxb0d61 rxb0d60 94 f6bh rxb0d5 rxb0d57 rxb0d56 rxb0d55 rxb0d54 rxb0d53 rxb0d52 rxb0d51 rxb0d50 94 f6ah rxb0d4 rxb0d47 rxb0d46 rxb0d45 rxb0d44 rxb0d43 rxb0d42 rxb0d41 rxb0d40 94 f69h rxb0d3 rxb0d37 rxb0d36 rxb0d35 rxb0d34 rxb0d33 rxb0d32 rxb0d31 rxb0d30 94 f68h rxb0d2 rxb0d27 rxb0d26 rxb0d25 rxb0d24 rxb0d23 rxb0d22 rxb0d21 rxb0d20 94 f67h rxb0d1 rxb0d17 rxb0d16 rxb0d15 rxb0d14 rxb0d13 rxb0d12 rxb0d11 rxb0d10 94 f66h rxb0d0 rxb0d07 rxb0d06 rxb0d05 rxb0d04 rxb0d03 rxb0d02 rxb0d01 rxb0d00 94 f65h rxb0dlc ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 94 f64h rxb0eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 94 f63h rxb0eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 94 f62h rxb0sidl sid2 sid1 sid0 srr exid ?eid17eid1694 f61h rxb0sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 94 f60h rxb0con rxful rxm1 rxm0 ? rxrtrro rxb0dben jtoff filhit0 94 f60h rxb0con rxful rxm1 rtrro filhit4 filhit3 filhit2 filhit1 filhit0 94 f5fh cm1con con coe cpol evpol1 evpol0 cref cch1 cch0 94 f5eh cm2con con coe cpol evpol1 evpol0 cref cch1 cch0 94 f5dh ancon0 ansel7 ansel6 ansel5 ansel4 ansel3 ansel2 ansel1 ansel0 94 f5ch ancon1 ? ansel14 ansel13 ansel12 ansel11 ansel10 ansel9 ansel8 94 f5bh wpub wpub7 wpub6 wpub5 wpub4 wpub3 wpub2 wpub1 wpub0 94 f5ah iocb iocb7 iocb6 iocb5 iocb4 ? ? ? ?94 f59h pmd0 ccp5md ccp4md ccp3md ccp2md ccp1md uart2md uart1md sspmd 94 f58h pmd1 pspmd ctmumd adcmd tmr4md tmr3md tmr2md tmr1md tmr0md 95 f57h pmd2 ? ? ? ? modmd ecanmd cmp2md cmp1md 95 f56h padcfg1 rdpu repu rfpu rgpu ? ? ? ctmuds 95 f55h ctmuconh ctmuen ? ctmusidl tgen edgen edgseqen idissen cttrig 95 f54h ctmuconl edg2pol edg2sel1 edg2sel0 edg 1pol edg1sel1 edg1sel0 edg2stat edg1stat 95 f53h ctmuicon itrim5 itrim4 itrim3 itrim2 itrim1 itrim0 irng1 irng0 95 f52h ccpr2h capture/compare/pwm register 2 high byte 95 f51h ccpr2l capture/compare/pwm register 2 low byte 95 f50h ccp2con ? ? dc2b1 dc2b0 ccp2m3 ccp2m2 ccp2m1 ccp2m0 95 f4fh ccpr3h capture/compare/pwm register 3 high byte 95 f4eh ccpr3l capture/compare/pwm register 3 low byte 95 f4dh ccp3con ? ? dc3b1 d32b0 ccp3m3 ccp3m2 ccp3m1 ccp3m0 95 f4ch ccpr4h capture/compare/pwm register 4 high byte 95 f4bh ccpr4l capture/compare/pwm register 4 low byte 95 f4ah ccp4con ? ? dc4b1 dc4b0 ccp4m3 ccp4m2 ccp4m1 ccp4m0 95 f49h ccpr5h capture/compare/pwm register 5 high byte 95 f48h ccpr5l capture/compare/pwm register 5 low byte 95 f47h ccp5con ? ? dc5b1 dc5b0 ccp5m3 ccp5m2 ccp5m1 ccp5m0 95 f46h pspcon ibf obf ibov pspmode ? ? ? ?95 f45h mdcon mden mdoe mdslr mdopol mdo ? ?mdbit95 f44h mdsrc mdsodis ? ? ? mdsrc3 mdsrc2 mdsrc1 mdsrc0 95 f43h mdcarh mdchodis mdchpol mdchsync ? mdch3 mdch2 mdch1 mdch0 95 f42h mdcarl mdclodis mdclpol mdclsync ? mdcl3 mdcl2 mdcl1 mdcl0 95 f41h unimplemented ? f40h unimplemented ? f3fh cancon_ro0 cancon_ro0 95 f3eh canstat_ro0 canstat_ro0 95 f3dh rxb1d7 rxb1d77 rxb1d76 rxb1d75 rxb1d74 rxb1d73 rxb1d72 rxb1d71 rxb1d70 95 f3ch rxb1d6 rxb1d67 rxb1d66 rxb1d65 rxb1d64 rxb1d63 rxb1d62 rxb1d61 rxb1d60 95 table 6-2: pic18f66k80 family register file summary (continued) addr. file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor on page
? 2011 microchip technology inc. ds39977d-page 121 pic18f66k80 family f3bh rxb1d5 rxb1d57 rxb1d56 rxb1d55 rxb1d54 rxb1d53 rxb1d52 rxb1d51 rxb1d50 95 f3ah rxb1d4 rxb1d47 rxb1d46 rxb1d45 rxb1d44 rxb1d43 rxb1d42 rxb1d41 rxb1d40 95 f39h rxb1d3 rxb1d37 rxb1d36 rxb1d35 rxb1d34 rxb1d33 rxb1d32 rxb1d31 rxb1d30 95 f38h rxb1d2 rxb1d27 rxb1d26 rxb1d25 rxb1d24 rxb1d23 rxb1d22 rxb1d21 rxb1d20 95 f37h rxb1d1 rxb1d17 rxb1d16 rxb1d15 rxb1d14 rxb1d13 rxb1d12 rxb1d11 rxb1d10 95 f36h rxb1d0 rxb1d07 rxb1d06 rxb1d05 rxb1d04 rxb1d03 rxb1d02 rxb1d01 rxb1d00 95 f35h rxb1dlc ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 95 f34h rxb1eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 96 f33h rxb1eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 96 f32h rxb1sidl sid2 sid1 sid0 srr exid ?eid17eid1696 f31h rxb1sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 96 f30h rxb1con rxful rxm1 rxm0 ? rxrtrro rxbodben jtoff filhit0 96 f30h rxb1con rxful rxm1 rtrro filhit4 filhit3 filhit2 filhit1 filhit0 96 f2fh cancon_ro1 cancon_ro1 96 f2eh canstat_ro1 canstat_ro1 96 f2dh txb0d7 txb0d77 txb0d76 txb0d75 txb0d74 txb0d73 txb0d72 txb0d71 txb0d70 96 f2ch txb0d6 txb0d67 txb0d66 txb0d65 txb0d64 txb0d63 txb0d62 txb0d61 txb0d60 96 f2bh txb0d5 txb0d57 txb0d56 txb0d55 txb0d54 txb0d53 txb0d52 txb0d51 txb0d50 96 f2ah txb0d4 txb0d47 txb0d46 txb0d45 txb0d44 txb0d43 txb0d42 txb0d41 txb0d40 96 f29h txb0d3 txb0d37 txb0d36 txb0d35 txb0d34 txb0d33 txb0d32 txb0d31 txb0d30 96 f28h txb0d2 txb0d27 txb0d26 txb0d25 txb0d24 txb0d23 txb0d22 txb0d21 txb0d20 96 f27h txb0d1 txb0d17 txb0d16 txb0d15 txb0d14 txb0d13 txb0d12 txb0d11 txb0d10 96 f26h txb0d0 txb0d07 txb0d06 txb0d05 txb0d04 txb0d03 txb0d02 txb0d01 txb0d00 96 f25h txb0dlc ?txrtr ? ? dlc3dlc2dlc1dlc0 96 f24h txb0eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 96 f23h txb0eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 96 f22h txb0sidl sid2 sid1 sid0 srr exid ?eid17eid1696 f21h txb0sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 96 f20h txb0con txbif txabt txlarb txerr txreq ? txpri1 txpri0 96 f1fh cancon_ro2 cancon_ro2 96 f1eh canstat_ro2 canstat_ro2 96 f1dh txb1d7 txb1d77 txb1d76 txb1d75 txb1d74 txb1d73 txb1d72 txb1d71 txb1d70 96 f1ch txb1d6 txb1d67 txb1d66 txb1d65 txb1d64 txb1d63 txb1d62 txb1d61 txb1d60 96 f1bh txb1d5 txb1d57 txb1d56 txb1d55 txb1d54 txb1d53 txb1d52 txb1d51 txb1d50 96 f1ah txb1d4 txb1d47 txb1d46 txb1d45 txb1d44 txb1d43 txb1d42 txb1d41 txb1d40 96 f19h txb1d3 txb1d37 txb1d36 txb1d35 txb1d34 txb1d33 txb1d32 txb1d31 txb1d30 96 f18h txb1d2 txb1d27 txb1d26 txb1d25 txb1d24 txb1d23 txb1d22 txb1d21 txb1d20 96 f17h txb1d1 txb1d17 txb1d16 txb1d15 txb1d14 txb1d13 txb1d12 txb1d11 txb1d10 96 f16h txb1d0 txb1d07 txb1d06 txb1d05 txb1d04 txb1d03 txb1d02 txb1d01 txb1d00 96 f15h txb1dlc ?txrtr ? ? dlc3dlc2dlc1dlc0 96 f14h txb1eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 96 f13h txb1eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 96 f12h txb1sidl sid2 sid1 sid0 srr exid ?eid17eid1696 f11h txb1sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 96 f10h txb1con txbif txabt txlarb txerr txreq ? txpri1 txpri0 96 f0fh cancon_ro3 cancon_ro3 96 f0eh canstat_ro3 canstat_ro3 96 f0dh txb2d7 txb2d77 txb2d76 txb2d75 txb2d74 txb2d73 txb2d72 txb2d71 txb2d70 96 f0ch txb2d6 txb2d67 txb2d66 txb2d65 txb2d64 txb2d63 txb2d62 txb2d61 txb2d60 97 f0bh txb2d5 txb2d57 txb2d56 txb2d55 txb2d54 txb2d53 txb2d52 txb2d51 txb2d50 97 f0ah txb2d4 txb2d47 txb2d46 txb2d45 txb2d44 txb2d43 txb2d42 txb2d41 txb2d40 ? table 6-2: pic18f66k80 family register file summary (continued) addr. file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor on page
pic18f66k80 family ds39977d-page 122 ? 2011 microchip technology inc. f09h txb2d3 txb2d37 txb2d36 txb2d35 txb2d34 txb2d33 txb2d32 txb2d31 txb2d30 97 f08h txb2d2 txb2d27 txb2d26 txb2d25 txb2d24 txb2d23 txb2d22 txb2d21 txb2d20 97 f07h txb2d1 txb2d17 txb2d16 txb2d15 txb2d14 txb2d13 txb2d12 txb2d11 txb2d10 97 f06h txb2d0 txb2d07 txb2d06 txb2d05 txb2d04 txb2d03 txb2d02 txb2d01 txb2d00 97 f05h txb2dlc ?txrtr ? ? dlc3dlc2dlc1dlc0 97 f04h txb2eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 97 f03h txb2eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 97 f02h txb2sidl sid2 sid1 sid0 srr exid ?eid17eid1697 f01h txb2sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 97 f00h txb2con txbif txabt txlarb txerr txreq ? txpri1 txpri0 97 effh rxm1eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 97 efeh rxm1eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 97 efdh rxm1sidl sid2 sid1 sid0 ?exiden ?eid17eid1697 efch rxm1sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 97 efbh rxm0eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 97 efah rxm0eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 97 ef9h rxm0sidl sid2 sid1 sid0 ?exiden ?eid17eid1697 ef8h rxm0sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 97 ef7h rxf5eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 97 ef6h rxf5eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 97 ef5h rxf5sidl sid2 sid1 sid0 ?exiden ?eid17eid1697 ef4h rxf5sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 97 ef3h rxf4eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 97 ef2h rxf4eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 97 ef1h rxf4sidl sid2 sid1 sid0 ?exiden ?eid17eid1697 ef0h rxf4sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 98 eefh rxf3eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 98 eeeh rxf3eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 98 eedh rxf3sidl sid2 sid1 sid0 ?exiden ?eid17eid1698 eech rxf3sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 98 eebh rxf2eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 98 eeah rxf2eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 98 ee9h rxf2sidl sid2 sid1 sid0 ?exiden ?eid17eid1698 ee8h rxf2sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 98 ee7h rxf1eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 98 ee6h rxf1eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 98 ee5h rxf1sidl sid2 sid1 sid0 ?exiden ?eid17eid1698 ee4h rxf1sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 98 ee3h rxf0eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 98 ee2h rxf0eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 98 ee1h rxf0sidl sid2 sid1 sid0 ?exiden ?eid17eid1698 ee0h rxf0sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 98 edfh cancon_ro4 cancon_ro4 98 edeh canstat_ro4 canstat_ro4 98 eddh b5d7 b5d77 b5d76 b5d75 b5d74 b5d73 b5d72 b5d71 b5d70 98 edch b5d6 b5d67 b5d66 b5d65 b5d64 b5d63 b5d62 b5d61 b5d60 98 edbh b5d5 b5d57 b5d56 b5d55 b5d54 b5d53 b5d52 b5d51 b5d50 98 edah b5d4 b5d47 b5d46 b5d45 b5d44 b5d43 b5d42 b5d41 b5d40 98 ed9h b5d3 b5d37 b5d36 b5d35 b5d34 b5d33 b5d32 b5d31 b5d30 98 ed8h b5d2 b5d27 b5d26 b5d25 b5d24 b5d23 b5d22 b5d21 b5d20 98 ed7h b5d1 b5d17 b5d16 b5d15 b5d14 b5d13 b5d12 b5d11 b5d10 98 table 6-2: pic18f66k80 family register file summary (continued) addr. file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor on page
? 2011 microchip technology inc. ds39977d-page 123 pic18f66k80 family ed6h b5d0 b5d07 b5d06 b5d05 b5d04 b5d03 b5d02 b5d01 b5d00 98 ed5h b5dlc ?txrtr ? ? dlc3dlc2dlc1dlc0 98 ed4h b5eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 98 ed3h b5eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 98 ed2h b5sidl sid2 sid1 sid0 srr exid ?eid17eid1698 ed1h b5sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 98 ed0h b5con txbif txabt txlarb txerr txreq ? txpri1 txpri0 98 ecfh cancon_ro5 cancon_ro5 98 eceh canstat_ro5 canstat_ro5 99 ecdh b4d7 b4d77 b4d76 b4d75 b4d74 b4d73 b4d72 b4d71 b4d70 99 ecch b4d6 b4d67 b4d66 b4d65 b4d64 b4d63 b4d62 b4d61 b4d60 99 ecbh b4d5 b4d57 b4d56 b4d55 b4d54 b4d53 b4d52 b4d51 b4d50 99 ecah b4d4 b4d47 b4d46 b4d45 b4d44 b4d43 b4d42 b4d41 b4d40 99 ec9h b4d3 b4d37 b4d36 b4d35 b4d34 b4d33 b4d32 b4d31 b4d30 99 ec8h b4d2 b4d27 b4d26 b4d25 b4d24 b4d23 b4d22 b4d21 b4d20 99 ec7h b4d1 b4d17 b4d16 b4d15 b4d14 b4d13 b4d12 b4d11 b4d10 99 ec6h b4d0 b4d07 b4d06 b4d05 b4d04 b4d03 b4d02 b4d01 b4d00 99 ec5h b4dlc ?txrtr ? ? dlc3dlc2dlc1dlc0 99 ec4h b4eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 99 ec3h b4eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 99 ec2h b4sidl sid2 sid1 sid0 srr exid ?eid17eid1699 ec1h b4sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 99 ec0h b4con txbif txabt txlarb txerr txreq ? txpri1 txpri0 99 ebfh cancon_ro6 cancon_ro6 99 ebeh canstat_ro6 canstat_ro6 99 ebdh b3d7 b3d77 b3d76 b3d75 b3d73 b3d73 b3d72 b3d71 b3d70 99 ebch b3d6 b3d67 b3d66 b3d65 b3d63 b3d63 b3d62 b3d61 b3d60 99 ebbh b3d5 b3d57 b3d56 b3d55 b3d53 b3d53 b3d52 b3d51 b3d50 99 ebah b3d4 b3d47 b3d46 b3d45 b3d43 b3d43 b3d42 b3d41 b3d40 99 eb9h b3d3 b3d37 b3d36 b3d35 b3d33 b3d33 b3d32 b3d31 b3d30 99 eb8h b3d2 b3d27 b3d26 b3d25 b3d23 b3d23 b3d22 b3d21 b3d20 99 eb7h b3d1 b3d17 b3d16 b3d15 b3d13 b3d13 b3d12 b3d11 b3d10 99 eb6h b3d0 b3d07 b3d06 b3d05 b3d03 b3d03 b3d02 b3d01 b3d00 99 eb5h b3dlc ?txrtr ? ? dlc3dlc2dlc1dlc0 99 eb4h b3eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 99 eb3h b3eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 99 eb2h b3sidl sid2 sid1 sid0 srr exid ?eid17eid1699 eb1h b3sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 99 eb0h b3con txbif txabt txlarb txerr txreq ? txpri1 txpri0 99 eafh cancon_ro7 cancon_ro7 99 eaeh canstat_ro7 canstat_ro7 99 eadh b2d7 b2d77 b2d76 b2d75 b2d72 b2d73 b2d72 b2d71 b2d70 99 each b2d6 b2d67 b2d66 b2d65 b2d62 b2d63 b2d62 b2d61 b2d60 99 eabh b2d5 b2d57 b2d56 b2d55 b2d52 b2d53 b2d52 b2d51 b2d50 100 eaah b2d4 b2d47 b2d46 b2d45 b2d42 b2d43 b2d42 b2d41 b2d40 100 ea9h b2d3 b2d37 b2d36 b2d35 b2d32 b2d33 b2d32 b2d31 b2d30 100 ea8h b2d2 b2d27 b2d26 b2d25 b2d22 b2d23 b2d22 b2d21 b2d20 100 ea7h b2d1 b2d17 b2d16 b2d15 b2d12 b2d13 b2d12 b2d11 b2d10 100 ea6h b2d0 b2d07 b2d06 b2d05 b2d02 b2d03 b2d02 b2d01 b2d00 100 ea5h b2dlc ?txrtr ? ? dlc3dlc2dlc1dlc0 100 ea4h b2eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 100 table 6-2: pic18f66k80 family register file summary (continued) addr. file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor on page
pic18f66k80 family ds39977d-page 124 ? 2011 microchip technology inc. ea3h b2eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 100 ea2h b2sidl sid2 sid1 sid0 srr exid ?eid17eid16 ea1h b2sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 100 ea0h b2con txbif txabt txlarb txerr txreq ? txpri1 txpri0 100 e9fh cancon_ro8 cancon_ro8 100 e9eh canstat_ro8 canstat_ro8 100 e9dh b1d7 b1d77 b1d76 b1d75 b1d71 b1d73 b1d72 b1d71 b1d70 100 e9ch b1d6 b1d67 b1d66 b1d65 b1d61 b1d63 b1d62 b1d61 b1d60 100 e9bh b1d5 b1d57 b1d56 b1d55 b1d51 b1d53 b1d52 b1d51 b1d50 100 e9ah b1d4 b1d47 b1d46 b1d45 b1d41 b1d43 b1d42 b1d41 b1d40 100 e99h b1d3 b1d37 b1d36 b1d35 b1d31 b1d33 b1d32 b1d31 b1d30 100 e98h b1d2 b1d27 b1d26 b1d25 b1d21 b1d23 b1d22 b1d21 b1d20 100 e97h b1d1 b1d17 b1d16 b1d15 b1d11 b1d13 b1d12 b1d11 b1d10 100 e96h b1d0 b1d07 b1d06 b1d05 b1d01 b1d03 b1d02 b1d01 b1d00 100 e95h b1dlc ?txrtr ? ? dlc3dlc2dlc1dlc0 100 e94h b1eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 100 e93h b1eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 100 e92h b1sidl sid2 sid1 sid0 srr exid ? eid17 eid16 100 e91h b1sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 100 e90h b1con txbif txabt txlarb txerr txreq rtren txpri1 txpri0 100 e90h b1con rxful rxm1 rxrtrro filhit4 filhit3 filhit2 filhit1 filhit0 100 e8fh cancon_ro9 cancon_ro9 100 e8eh canstat_ro9 canstat_ro9 100 e8dh b0d7 b0d77 b0d76 b0d75 b0d70 b0d73 b0d72 b0d71 b0d70 100 e8ch b0d6 b0d67 b0d66 b0d65 b0d60 b0d63 b0d62 b0d61 b0d60 100 e8bh b0d5 b0d57 b0d56 b0d55 b0d50 b0d53 b0d52 b0d51 b0d50 100 e8ah b0d4 b0d47 b0d46 b0d45 b0d40 b0d43 b0d42 b0d41 b0d40 100 e89h b0d3 b0d37 b0d36 b0d35 b0d30 b0d33 b0d32 b0d31 b0d30 100 e88h b0d2 b0d27 b0d26 b0d25 b0d20 b0d23 b0d22 b0d21 b0d20 101 e87h b0d1 b0d17 b0d16 b0d15 b0d10 b0d13 b0d12 b0d11 b0d10 101 e86h b0d0 b0d07 b0d06 b0d05 b0d00 b0d03 b0d02 b0d01 b0d00 101 e85h b0dlc ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 101 e84h b0eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 101 e83h b0eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 101 e82h b0sidl sid2 sid1 sid0 srr exid ? eid17 eid16 101 e81h b0sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 101 e80h b0con txbif txabt txlarb txerr txreq rtren txpri1 txpri0 101 e80h b0con rtxful rxm1 rxrtrro filhit4 filhit3 filhit2 filhit1 filhit0 101 e7fh txbie ? ? ? can tx buffer interrupt enable ? ?101 e7eh bie0 can buffer interrupt enable 101 e7dh bsel0 mode select register 0 ? ?101 e7ch msel3 can mask select register 3 101 e7bh msel2 can mask select register 2 101 e7ah msel1 can mask select register 1 101 e79h msel0 can mask select register 0 101 e78h rxfbcon7 can buffer 15/14 pointer register 101 e77h rxfbcon6 can buffer 13/12 pointer register 101 e76h rxfbcon5 can buffer 11/10 pointer register 101 e75h rxfbcon4 can buffer 9/8 pointer register 101 e74h rxfbcon3 can buffer 7/6 pointer register 101 e73h rxfbcon2 can buffer 5/4 pointer register 101 table 6-2: pic18f66k80 family register file summary (continued) addr. file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor on page
? 2011 microchip technology inc. ds39977d-page 125 pic18f66k80 family e72h rxfbcon1 can buffer 3/2 pointer register 101 e71h rxfbcon0 can buffer 1/0 pointer register 101 e70h sdflc ? ? ? can device net count register 101 e6fh rxf15eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 101 e6eh rxf15eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 101 e6dh rxf15sidl sid2 sid1 sid0 srr exid ? eid17 eid16 101 e6ch rxf15sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 101 e6bh rxf14eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 101 e6ah rxf14eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 101 e69h rxf14sidl sid2 sid1 sid0 srr exid ? eid17 eid16 101 e68h rxf14sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 101 e67h rxf13eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 101 e66h rxf13eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 102 e65h rxf13sidl sid2 sid1 sid0 srr exid ? eid17 eid16 102 e64h rxf13sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 102 e63h rxf12eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 102 e62h rxf12eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 102 e61h rxf12sidl sid2 sid1 sid0 srr exid ? eid17 eid16 102 e60h rxf12sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 102 e5fh rxf11eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 102 e5eh rxf11eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 102 e5dh rxf11sidl sid2 sid1 sid0 srr exid ? eid17 eid16 102 e5ch rxf11sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 102 e5bh rxf10eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 102 e5ah rxf10eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 102 e59h rxf10sidl sid2 sid1 sid0 srr exid ? eid17 eid16 102 e58h rxf10sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 102 e57h rxf9eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 102 e56h rxf9eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 102 e55h rxf9sidl sid2 sid1 sid0 srr exid ? eid17 eid16 102 e54h rxf9sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 102 e53h rxf8eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 102 e52h rxf8eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 102 e51h rxf8sidl sid2 sid1 sid0 srr exid ? eid17 eid16 102 e50h rxf8sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 102 e4fh rxf7eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 102 e4eh rxf7eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 102 e4dh rxf7sidl sid2 sid1 sid0 srr exid ? eid17 eid16 102 e4ch rxf7sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 102 e4bh rxf6eidl eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 102 e4ah rxf6eidh eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 102 e49h rxf6sidl sid2 sid1 sid0 srr exid ? eid17 eid16 102 e48h rxf6sidh sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 102 e47h rxfcon0 can receive filter control register 0 102 e46h rxfcon1 can receive filter control register 1 102 e45h brgcon3 wakdis wakfil ? ? ? seg2ph2 seg2ph1 seg2ph0 102 e44h brgcon2 seg2phts sam seg1ph2 seg1ph1 seg1ph0 prseg2 prseg1 prseg0 103 e43h brgcon1 sjw1 sjw0 brp5 brp4 brp3 brp2 brp1 brp0 103 e42h txerrcnt tec7 tec6 tec5 tec4 tec3 tec2 tec1 tec0 103 e41h rxerrcnt rec7 rec6 rec5 rec4 rec3 rec2 rec1 rec0 103 table 6-2: pic18f66k80 family register file summary (continued) addr. file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor on page
pic18f66k80 family ds39977d-page 126 ? 2011 microchip technology inc. 6.3.5 status register the status register, shown in register 6-2 , contains the arithmetic status of the alu. the status register can be the operand for any instruction, as with any other register. if the status register is the destination for an instruction that affects the z, dc, c, ov or n bits, the write to these five bits is disabled. these bits are set or cleared according to the device logic. therefore, the result of an instruction with the status register as destination may be different than intended. for example, clrf status will set the z bit but leave the other bits unchanged. the status register then reads back as ? 000u u1uu ?. it is recommended, therefore, that only bcf, bsf, swapf, movff and movwf instructions be used to alter the status register because these instructions do not affect the z, c, dc, ov or n bits in the status register. for other instructions not affecting any status bits, see the instruction set summaries in table 29-2 and table 29-3 . note: the c and dc bits operate, in subtraction, as borrow and digit borrow bits, respectively. register 6-2: status register u-0 u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x ? ? ?novzdc (1) c (2) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4 n: negative bit this bit is used for signed arithmetic (2?s complement). it indicates whether the result was negative (alu msb = 1 ). 1 = result was negative 0 = result was positive bit 3 ov: overflow bit this bit is used for signed arithmetic (2?s complement). it indicates an overflow of the seven-bit magnitude which causes the sign bit (bit 7) to change state. 1 = overflow occurred for signed arithmetic (in this arithmetic operation) 0 = no overflow occurred bit 2 z: zero bit 1 = the result of an arithmetic or logic operation is zero 0 = the result of an arithmetic or logic operation is not zero bit 1 dc: digit carry/borrow bit (1) for addwf, addlw, sublw and subwf instructions: 1 = a carry-out from the 4th low-order bit of the result occurred 0 = no carry-out from the 4th low-order bit of the result bit 0 c: carry/borrow bit (2) for addwf, addlw, sublw and subwf instructions: 1 = a carry-out from the most significant bit of the result occurred 0 = no carry-out from the most significant bit of the result occurred note 1: for borrow, the polarity is reversed. a subtraction is ex ecuted by adding the 2?s complement of the second operand. for rotate ( rrf, rlf ) instructions, this bit is loaded with eit her bit 4 or bit 3 of the source register. 2: for borrow, the polarity is reversed. a subtraction is executed by adding the 2?s complement of the second operand. for rotate ( rrf, rlf ) instructions, this bit is loaded with either the high or low-order bit of the source register.
? 2011 microchip technology inc. ds39977d-page 127 pic18f66k80 family 6.4 data addressing modes while the program memory can be addressed in only one way, through the program counter, information in the data memory space can be addressed in several ways. for most instructions, the addressing mode is fixed. other instructions may use up to three modes, depending on which operands are used and whether or not the extended instruction set is enabled. the addressing modes are: ? inherent ? literal ?direct ?indirect an additional addressing mode, indexed literal offset, is available when the extended instruction set is enabled (xinst configuration bit = 1 ). for details on this mode?s operation, see section 6.6.1 ?indexed addressing with literal offset? . 6.4.1 inherent and literal addressing many pic18 control instructions do not need any argument at all. they either perform an operation that globally affects the device or they operate implicitly on one register. this addressing mode is known as inherent addressing. examples of this mode include sleep , reset and daw . other instructions work in a similar way, but require an additional explicit argument in the opcode. this method is known as the literal addressing mode because the instructions require some literal value as an argument. examples of this include addlw and movlw , which respectively, add or move a literal value to the w register. other examples include call and goto , which include a 20-bit program memory address. 6.4.2 direct addressing direct addressing specifies all or part of the source and/or destination address of the operation within the opcode itself. the options are specified by the arguments accompanying the instruction. in the core pic18 instruction set, bit-oriented and byte-oriented instructions use some version of direct addressing by default. all of these instructions include some 8-bit literal address as their least significant byte. this address specifies the instruction?s data source as either a register address in one of the banks of data ram (see section 6.3.3 ?general purpose register file? ) or a location in the access bank (see section 6.3.2 ?access bank? ). the access ram bit, ?a?, determines how the address is interpreted. when ?a? is ? 1 ?, the contents of the bsr ( section 6.3.1 ?bank select register? ) are used with the address to determine the complete 12-bit address of the register. when ?a? is ? 0 ?, the address is interpreted as being a register in the access bank. addressing that uses the access ram is sometimes also known as direct forced addressing mode. a few instructions, such as movff , include the entire 12-bit address (either source or destination) in their opcodes. in these cases, the bsr is ignored entirely. the destination of the operation?s results is determined by the destination bit, ?d?. when ?d? is ? 1 ?, the results are stored back in the source register, overwriting its origi- nal contents. when ?d? is ? 0 ?, the results are stored in the w register. instructions without the ?d? argument have a destination that is implicit in the instruction, either the target register being operated on or the w register. 6.4.3 indirect addressing indirect addressing allows the user to access a location in data memory without giving a fixed address in the instruction. this is done by using file select registers (fsrs) as pointers to the locations to be read or written to. since the fsrs are themselves located in ram as special function registers, they can also be directly manipulated under program control. this makes fsrs very useful in implementing data structures such as tables and arrays in data memory. the registers for indirect addressing are also implemented with indirect file operands (indfs) that permit automatic manipulation of the pointer value with auto-incrementing, auto-decrementing or offsetting with another value. this allows for efficient code using loops, such as the example of clearing an entire ram bank in example 6-5 . it also enables users to perform indexed addressing and other stack pointer operations for program memory in data memory. example 6-5: how to clear ram (bank 1) using indirect addressing note: the execution of some instructions in the core pic18 instruction set are changed when the pic18 extended instruction set is enabled. for more information, see section 6.6 ?data memory and the extended instruction set? . lfsr fsr0, 100h ; next clrf postinc0 ; clear indf ; register then ; inc pointer btfss fsr0h, 1 ; all done with ; bank1? bra next ; no, clear next continue ; yes, continue
pic18f66k80 family ds39977d-page 128 ? 2011 microchip technology inc. 6.4.3.1 fsr registers and the indf operand at the core of indirect addressing are three sets of registers: fsr0, fsr1 and fsr2. each represents a pair of 8-bit registers: fsrnh and fsrnl. the four upper bits of the fsrnh register are not used, so each fsr pair holds a 12-bit value. this represents a value that can address the entire range of the data memory in a linear fashion. the fsr register pairs, then, serve as pointers to data memory locations. indirect addressing is accomplished with a set of indi- rect file operands, indf0 through indf2. these can be thought of as ?virtual? registers. the operands are mapped in the sfr space, but are not physically imple- mented. reading or writing to a particular indf register actually accesses its corresponding fsr register pair. a read from indf1, for example, reads the data at the address indicated by fsr1h:fsr1l. instructions that use the indf registers as operands actually use the contents of their corresponding fsr as a pointer to the instruction?s target. the indf operand is just a convenient way of using the pointer. because indirect addressing uses a full 12-bit address, data ram banking is not necessary. thus, the current contents of the bsr and the access ram bit have no effect on determining the target address. figure 6-8: indirect addressing fsr1h:fsr1l 0 7 data memory 000h 100h 200h 300h f00h e00h fffh bank 0 bank 1 bank 2 bank 14 bank 15 bank 3 through bank 13 addwf, indf1, 1 0 7 using an instruction with one of the indirect addressing registers as the operand.... ...uses the 12-bit address stored in the fsr pair associated with that register.... ...to determine the data memory location to be used in that operation. in this case, the fsr1 pair contains fcch. this means the contents of location fcch will be added to that of the w register and stored back in fcch. xxxx 1111 11001100
? 2011 microchip technology inc. ds39977d-page 129 pic18f66k80 family 6.4.3.2 fsr registers and postinc, postdec, preinc and plusw in addition to the indf operand, each fsr register pair also has four additional indirect operands. like indf, these are ?virtual? registers that cannot be indirectly read or written to. accessing these registers actually accesses the associated fsr register pair, but also performs a specific action on its stored value. these operands are: ? postdec ? accesses the fsr value, then automatically decrements it by ? 1 ? afterwards ? postinc ? accesses the fsr value, then automatically increments it by ? 1 ? afterwards ? preinc ? increments the fsr value by ? 1 ?, then uses it in the operation ? plusw ? adds the signed value of the w register (range of -127 to 128) to that of the fsr and uses the new value in the operation in this context, accessing an indf register uses the value in the fsr registers without changing them. similarly, accessing a plusw register gives the fsr value, offset by the value in the w register, with neither value actually changed in the operation. accessing the other virtual registers changes the value of the fsr registers. operations on the fsrs with postdec, postinc and preinc affect the entire register pair. rollovers of the fsrnl register, from ffh to 00h, carry over to the fsrnh register. on the other hand, results of these operations do not change the value of any flags in the status register (for example, z, n and ov bits). the plusw register can be used to implement a form of indexed addressing in the data memory space. by manipulating the value in the w register, users can reach addresses that are fixed offsets from pointer addresses. in some applications, this can be used to implement some powerful program control structure, such as software stacks, inside of data memory. 6.4.3.3 operations by fsrs on fsrs indirect addressing operations that target other fsrs or virtual registers represent special cases. for example, using an fsr to point to one of the virtual registers will not result in successful operations. as a specific case, assume that the fsr0h:fsr0l registers contain fe7h, the address of indf1. attempts to read the value of the indf1, using indf0 as an operand, will return 00h. attempts to write to indf1, using indf0 as the operand, will result in a nop . on the other hand, using the virtual registers to write to an fsr pair may not occur as planned. in these cases, the value will be written to the fsr pair, but without any incrementing or decrementing. thus, writing to indf2 or postdec2 will write the same value to the fsr2h:fsr2l. since the fsrs are physical registers mapped in the sfr space, they can be manipulated through all direct operations. users should proceed cautiously when working on these registers, however, particularly if their code uses indirect addressing. similarly, operations by indirect addressing are gener- ally permitted on all other sfrs. users should exercise the appropriate caution, so that they do not inadvertently change settings that might affect the operation of the device. 6.5 program memory and the extended instruction set the operation of program memory is unaffected by the use of the extended instruction set. enabling the extended instruction set adds five additional two-word commands to the existing pic18 instruction set: addfsr , callw , movsf , movss and subfsr . these instructions are executed as described in section 6.2.4 ?two-word instructions? .
pic18f66k80 family ds39977d-page 130 ? 2011 microchip technology inc. 6.6 data memory and the extended instruction set enabling the pic18 extended instruction set (xinst configuration bit = 1 ) significantly changes certain aspects of data memory and its addressing. using the access bank for many of the core pic18 instructions introduces a new addressing mode for the data memory space. this mode also alters the behavior of indirect addressing using fsr2 and its associated operands. what does not change is just as important. the size of the data memory space is unchanged, as well as its linear addressing. the sfr map remains the same. core pic18 instructions can still operate in both direct and indirect addressing mode. inherent and literal instructions do not change at all. indirect addressing with fsr0 and fsr1 also remains unchanged. 6.6.1 indexed addressing with literal offset enabling the pic18 extended instruction set changes the behavior of indirect addressing using the fsr2 register pair and its associated file operands. under the proper conditions, instructions that use the access bank ? that is, most bit-oriented and byte-oriented instructions ? can invoke a form of indexed addressing using an offset specified in the instruction. this special addressing mode is known as indexed addressing with literal offset or the indexed literal offset mode. when using the extended instruction set, this addressing mode requires the following: ? use of the access bank (?a? = 0 ) ? a file address argument that is less than or equal to 5fh under these conditions, the file address of the instruction is not interpreted as the lower byte of an address (used with the bsr in direct addressing) or as an 8-bit address in the access bank. instead, the value is interpreted as an offset value to an address pointer specified by fsr2. the offset and the contents of fsr2 are added to obtain the target address of the operation. 6.6.2 instructions affected by indexed literal offset mode any of the core pic18 instructions that can use direct addressing are potentially affected by the indexed literal offset addressing mode. this includes all byte-oriented and bit-oriented instructions, or almost one-half of the standard pic18 instruction set. instruc- tions that only use inherent or literal addressing modes are unaffected. additionally, byte-oriented and bit-oriented instructions are not affected if they do not use the access bank (access ram bit = 1 ), or include a file address of 60h or above. instructions meeting these criteria will continue to execute as before. a comparison of the dif- ferent possible addressing modes when the extended instruction set is enabled is shown in figure 6-9 . those who desire to use byte-oriented or bit-oriented instructions in the indexed literal offset mode should note the changes to assembler syntax for this mode. this is described in more detail in section 29.2.1 ?extended instruction syntax? .
? 2011 microchip technology inc. ds39977d-page 131 pic18f66k80 family figure 6-9: comparing addressing options for bit-oriented and byte-oriented instructions (extended instruction set enabled) example instruction: addwf, f, d, a (opcode: 0010 01da ffff ffff ) when a = 0 and f ? 60h: the instruction executes in direct forced mode. ?f? is interpreted as a location in the access ram between 060h and fffh. this is the same as locations, f60h to fffh, (bank 15) of data memory. locations below 060h are not available in this addressing mode. when a = 0 and f ??? 5fh: the instruction executes in indexed literal offset mode. ?f? is interpreted as an offset to the address value in fsr2. the two are added together to obtain the address of the target register for the instruction. the address can be anywhere in the data memory space. note that in this mode, the correct syntax is now: addwf [k], d where ?k? is the same as ?f?. when a = 1 (all values of f): the instruction executes in direct mode (also known as direct long mode). ?f? is interpreted as a location in one of the 16 banks of the data memory space. the bank is designated by the bank select register (bsr). the address can be in any implemented bank in the data memory space. 000h 060h 100h f00h f40h fffh valid range 00h 60h ffh data memory access ram bank 0 bank 1 through bank 14 bank 15 sfrs 000h 060h 100h f00h f40h fffh data memory bank 0 bank 1 through bank 14 bank 15 sfrs fsr2h fsr2l ffffffff 001001da ffffffff 001001da 000h 060h 100h f00h f40h fffh data memory bank 0 bank 1 through bank 14 bank 15 sfrs for ?f? bsr 00000000
pic18f66k80 family ds39977d-page 132 ? 2011 microchip technology inc. 6.6.3 mapping the access bank in indexed literal offset mode the use of indexed literal offset addressing mode effectively changes how the lower part of access ram (00h to 5fh) is mapped. rather than containing just the contents of the bottom part of bank 0, this mode maps the contents from bank 0 and a user-defined ?window? that can be located anywhere in the data memory space. the value of fsr2 establishes the lower boundary of the addresses mapped into the window, while the upper boundary is defined by fsr2 plus 95 (5fh). addresses in the access ram above 5fh are mapped as previously described. (see section 6.3.2 ?access bank? .) an example of access bank remapping in this addressing mode is shown in figure 6-10 . remapping the access bank applies only to operations using the indexed literal offset mode. operations that use the bsr (access ram bit = 1 ) will continue to use direct addressing as before. any indirect or indexed addressing operation that explicitly uses any of the indirect file operands (including fsr2) will continue to operate as standard indirect addressing. any instruc- tion that uses the access bank, but includes a register address of greater than 05fh, will use direct addressing and the normal access bank map. 6.6.4 bsr in indexed literal offset mode although the access bank is remapped when the extended instruction set is enabled, the operation of the bsr remains unchanged. direct addressing, using the bsr to select the data memory bank, operates in the same manner as previously described. figure 6-10: remapping the access bank with indexed literal offset addressing data memory 000h 100h 200h f60h f00h fffh bank 1 bank 15 bank 2 through bank 14 sfrs 05fh addwf f, d, a fsr2h:fsr2l = 120h locations in the region from the fsr2 pointer (120h) to the pointer plus 05fh (17fh) are mapped to the bottom of the access ram (000h-05fh). special function registers at f60h through fffh are mapped to 60h through ffh, as usual. bank 0 addresses below 5fh are not available in this mode. they can still be addressed by using the bsr. access bank 00h ffh bank 0 sfrs bank 1 ?window? not accessible window example situation: 120h 17fh 5fh 60h
? 2011 microchip technology inc. ds39977d-page 133 pic18f66k80 family 7.0 flash program memory the flash program memory is readable, writable and erasable during normal operation over the entire v dd range. a read from program memory is executed on one byte at a time. a write to program memory is executed on blocks of 64 bytes at a time. program memory is erased in blocks of 64 bytes at a time. a bulk erase operation may not be issued from user code. writing or erasing program memory will cease instruction fetches until the operation is complete. the program memory cannot be accessed during the write or erase, therefore, code cannot execute. an internal programming timer terminates program memory writes and erases. a value written to program memory does not need to be a valid instruction. executing a program memory location that forms an invalid instruction results in a nop . 7.1 table reads and table writes in order to read and write program memory, there are two operations that allow the processor to move bytes between the program memory space and the data ram: ? table read ( tblrd ) ? table write ( tblwt ) the program memory space is 16 bits wide, while the data ram space is 8 bits wide. table reads and table writes move data between these two memory spaces through an 8-bit register (tablat). table read operations retrieve data from program memory and place it into the data ram space. figure 7-1 shows the operation of a table read with program memory and data ram. table write operations store data from the data memory space into holding registers in program memory. the procedure to write the contents of the holding registers into program memory is detailed in section 7.5 ?writing to flash program memory? . figure 7-2 shows the operation of a table write with program memory and data ram. table operations work with byte entities. a table block containing data, rather than program instructions, is not required to be word-aligned. therefore, a table block can start and end at any byte address. if a table write is being used to write executable code into program memory, program instructions will need to be word-aligned. figure 7-1: table read operation table pointer (1) table latch (8-bit) program memory tblptrh tblptrl tablat tblptru instruction: tblrd * note 1: table pointer register points to a byte in program memory. program memory (tblptr)
pic18f66k80 family ds39977d-page 134 ? 2011 microchip technology inc. figure 7-2: table write operation 7.2 control registers several control registers are used in conjunction with the tblrd and tblwt instructions. these include the: ? eecon1 register ? eecon2 register ? tablat register ? tblptr registers 7.2.1 eecon1 and eecon2 registers the eecon1 register ( register 7-1 ) is the control register for memory accesses. the eecon2 register, not a physical register, is used exclusively in the memory write and erase sequences. reading eecon2 will read all ? 0 ?s. the eepgd control bit determines if the access is a program or data eeprom memory access. when clear, any subsequent operations operate on the data eeprom memory. when set, any subsequent operations operate on the program memory. the cfgs control bit determines if the access is to the configuration registers or to program memory/data eeprom memory. when set, subsequent operations operate on configuration registers regardless of eepgd (see section 28.0 ?special features of the cpu? ). when clear, memory selection access is determined by eepgd. the free bit, when set, allows a program memory erase operation. when free is set, the erase operation is initiated on the next wr command. when free is clear, only writes are enabled. the wren bit, when set, allows a write operation. on power-up, the wren bit is clear. the wrerr bit is set in hardware when the wr bit is set and cleared when the internal programming timer expires and the write operation is complete. the wr control bit initiates write operations. the bit cannot be cleared, only set, in software. it is cleared in hardware at the completion of the write operation. table pointer (1) table latch (8-bit) tblptrh tblptrl tablat program memory (tblptr) tblptru instruction: tblwt * note 1: table pointer actually points to one of 64 holding registers, the address of which is determined by tblptrl<5:0>. the process for physically writing dat a to the program memory array is discussed in section 7.5 ?writing to flash program memory? . holding registers program memory note: during normal operation, the wrerr is read as ? 1 ?. this can indicate that a write operation was prematurely terminated by a reset, or a write operation was attempted improperly. note: the eeif interrupt flag bit (pir4<6>) is set when the write is complete. it must be cleared in software.
? 2011 microchip technology inc. ds39977d-page 135 pic18f66k80 family register 7-1: eecon1: eepr om control register 1 r/w-x r/w-x u-0 r/w-0 r/w-x r/w-0 r/s-0 r/s-0 eepgd cfgs ? free wrerr (1) wren wr rd bit 7 bit 0 legend: s = settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 eepgd: flash program or data eeprom memory select bit 1 = access flash program memory 0 = access data eeprom memory bit 6 cfgs: flash program/data eeprom or configuration select bit 1 = access configuration registers 0 = access flash program or data eeprom memory bit 5 unimplemented: read as ? 0 ? bit 4 free: flash row erase enable bit 1 = erase the program memory row addressed by tblptr on the next wr command (cleared by completion of erase operation) 0 = perform write-only bit 3 wrerr: flash program/data eeprom error flag bit (1) 1 = a write operation is prematurely terminated (any reset during self-timed programming in normal operation or an improper write attempt) 0 = the write operation completed bit 2 wren: flash program/data eeprom write enable bit 1 = allows write cycles to flash program/data eeprom 0 = inhibits write cycles to flash program/data eeprom bit 1 wr: write control bit 1 = initiates a data eeprom erase/write cycle or, a program memory erase cycle or write cycle. (the operation is self-timed and the bit is cleared by hardware once the write is complete. the wr bit can only be set (not cleared) in software.) 0 = write cycle to the eeprom is complete bit 0 rd: read control bit 1 = initiates an eeprom read (read takes one cycle. rd is cleared in hardware. the rd bit can only be set (not cleared) in software. rd bit cannot be set when eepgd = 1 or cfgs = 1 .) 0 = does not initiate an eeprom read note 1: when a wrerr occurs, the eepgd and cfgs bits are not cleared. this allows tracing of the error condition.
pic18f66k80 family ds39977d-page 136 ? 2011 microchip technology inc. 7.2.2 tablat ? table latch register the table latch (tablat) is an eight-bit register mapped into the sfr space. the table latch register is used to hold 8-bit data during data transfers between program memory and data ram. 7.2.3 tblptr ? table pointer register the table pointer (tblptr) register addresses a byte within the program memory. the tblptr is comprised of three sfr registers: table pointer upper byte, table pointer high byte and table pointer low byte (tblptru:tblptrh:tblptrl). these three regis- ters join to form a 22-bit wide pointer. the low-order 21 bits allow the device to address up to 2 mbytes of program memory space. the 22nd bit allows access to the device id, the user id and the configuration bits. the table pointer register, tblptr, is used by the tblrd and tblwt instructions. these instructions can update the tblptr in one of four ways, based on the table operation. these operations are shown in table 7-1 and only affect the low-order 21 bits. 7.2.4 table pointer boundaries tblptr is used in reads, writes and erases of the flash program memory. when a tblrd is executed, all 22 bits of the tblptr determine which byte is read from program memory into tablat. when a tblwt is executed, the six lsbs of the table pointer register (tblptr<5:0>) determine which of the 64 program memory holding registers is written to. when the timed write to program memory begins (via the wr bit), the 16 msbs of the tblptr (tblptr<21:6>) determine which program memory block of 64 bytes is written to. for more detail, see section 7.5 ?writing to flash program memory? . when an erase of program memory is executed, the 16 msbs of the table pointer register (tblptr<21:6>) point to the 64-byte block that will be erased. the least significant bits (tblptr<5:0>) are ignored. figure 7-3 describes the relevant boundaries of tblptr based on flash program memory operations. table 7-1: table pointer operations with tblrd and tblwt instructions figure 7-3: table pointer boundaries based on operation example operation on table pointer tblrd* tblwt* tblptr is not modified tblrd*+ tblwt*+ tblptr is incremented after the read/write tblrd*- tblwt*- tblptr is decremented after the read/write tblrd+* tblwt+* tblptr is incremented before the read/write 21 16 15 87 0 table erase/write table write table read ? tblptr<21:0> tblptrl tblptrh tblptru tblptr<5:0> tblptr<21:6>
? 2011 microchip technology inc. ds39977d-page 137 pic18f66k80 family 7.3 reading the flash program memory the tblrd instruction is used to retrieve data from program memory and places it into data ram. table reads from program memory are performed one byte at a time. tblptr points to a byte address in program space. executing tblrd places the byte pointed to into tablat. in addition, tblptr can be modified automatically for the next table read operation. the internal program memory is typically organized by words. the least significant bit of the address selects between the high and low bytes of the word. figure 7-4 shows the interface between the internal program memory and the tablat. figure 7-4: reads from flash program memory example 7-1: reading a flash program memory word (even byte address) program memory (odd byte address) tblrd tablat tblptr = xxxxx1 fetch instruction register (ir) read register tblptr = xxxxx0 movlw code_addr_upper ; load tblptr with the base movwf tblptru ; address of the word movlw code_addr_high movwf tblptrh movlw code_addr_low movwf tblptrl read_word tblrd*+ ; read into tablat and increment movf tablat, w ; get data movwf word_even tblrd*+ ; read into tablat and increment movf tablat, w ; get data movf word_odd
pic18f66k80 family ds39977d-page 138 ? 2011 microchip technology inc. 7.4 erasing flash program memory the erase blocks are 32 words or 64 bytes. word erase in the flash array is not supported. when initiating an erase sequence from the micro- controller itself, a block of 64 bytes of program memory is erased. the most significant 16 bits of the tblptr<21:6> point to the block being erased. the tblptr<5:0> bits are ignored. the eecon1 register commands the erase operation. the eepgd bit must be set to point to the flash program memory. the wren bit must be set to enable write operations. the free bit is set to select an erase operation. for protection, the write initiate sequence for eecon2 must be used. a long write is necessary for erasing the internal flash. instruction execution is halted while in a long write cycle. the long write will be terminated by the internal programming timer. 7.4.1 flash program memory erase sequence the sequence of events for erasing a block of internal program memory location is: 1. load the table pointer register with the address of row to be erased. 2. set the eecon1 register for the erase operation: ? set the eepgd bit to point to program memory ? clear the cfgs bit to access program memory ? set the wren bit to enable writes ? set the free bit to enable the erase 3. disable the interrupts. 4. write 55h to eecon2. 5. write 0aah to eecon2. 6. set the wr bit. this begins the row erase cycle. the cpu will stall for the duration of the erase for t iw . (see parameter d133a.) 7. re-enable interrupts. example 7-2: erasing a flash program memory row movlw code_addr_upper ; load tblptr with the base movwf tblptru ; address of the memory block movlw code_addr_high movwf tblptrh movlw code_addr_low movwf tblptrl erase_row bsf eecon1, eepgd ; point to flash program memory bcf eecon1, cfgs ; access flash program memory bsf eecon1, wren ; enable write to memory bsf eecon1, free ; enable row erase operation bcf intcon, gie ; disable interrupts required movlw 55h sequence movwf eecon2 ; write 55h movlw 0aah movwf eecon2 ; write 0aah bsf eecon1, wr ; start erase (cpu stall) bsf intcon, gie ; re-enable interrupts
? 2011 microchip technology inc. ds39977d-page 139 pic18f66k80 family 7.5 writing to flash program memory the programming blocks are 32 words or 64 bytes. word or byte programming is not supported. table writes are used internally to load the holding regis- ters needed to program the flash memory. there are 64 holding registers for programming by the table writes. since the table latch (tablat) is only a single byte, the tblwt instruction may need to be executed 64 times for each programming operation. all of the table write oper- ations will essentially be short writes because only the holding registers are written. at the end of updating the 64 or 128 holding registers, the eecon1 register must be written to in order to start the programming operation with a long write. the long write is necessary for programming the inter- nal flash. instruction execution is halted while in a long write cycle. the long write is terminated by the internal programming timer. the eeprom on-chip timer controls the write time. the write/erase voltages are generated by an on-chip charge pump, rated to operate over the voltage range of the device. figure 7-5: table writes to flash program memory 7.5.1 flash program memory write sequence the sequence of events for programming an internal program memory location should be: 1. read the 64 bytes into ram. 2. update the data values in ram as necessary. 3. load table pointer register with the address being erased. 4. execute the row erase procedure. 5. load table pointer register with the address of the first byte being written. 6. write the 64 bytes into the holding registers with auto-increment. 7. set the eecon1 register for the write operation: ? set the eepgd bit to point to program memory ? clear the cfgs bit to access program memory ? set the wren to enable byte writes 8. disable the interrupts. 9. write 55h to eecon2. 10. write 0aah to eecon2. 11. set the wr bit. this will begin the write cycle. the cpu will stall for duration of the write for t iw (see parameter d133a ). 12. re-enable the interrupts. 13. verify the memory (table read). an example of the required code is shown in example 7-3 on the following page. note: the default value of the holding registers on device resets and after write operations is ffh. a write of ffh to a holding register does not modify that byte. this means that individual bytes of program memory may be modified, provided that the change does not attempt to change any bit from a ? 0 ? to a ? 1 ?. when modifying individual bytes, it is not necessary to load all 64 holding registers before executing a write operation. tablat tblptr = xxxx3f tblptr = xxxxx1 tblptr = xxxxx0 write register tblptr = xxxxx2 program memory holding register holding register holding register holding register 8 8 8 8 note: before setting the wr bit, the table pointer address needs to be within the intended address range of the 64 bytes in the holding register.
pic18f66k80 family ds39977d-page 140 ? 2011 microchip technology inc. example 7-3: writing to flash program memory movlw size_of_block ; number of bytes in erase block movwf counter movlw buffer_addr_high ; point to buffer movwf fsr0h movlw buffer_addr_low movwf fsr0l movlw code_addr_upper ; load tblptr with the base movwf tblptru ; address of the memory block movlw code_addr_high movwf tblptrh movlw code_addr_low movwf tblptrl read_block tblrd*+ ; read into tablat, and inc movf tablat, w ; get data movwf postinc0 ; store data decfsz counter ; done? bra read_block ; repeat modify_word movlw data_addr_high ; point to buffer movwf fsr0h movlw data_addr_low movwf fsr0l movlw new_data_low ; update buffer word movwf postinc0 movlw new_data_high movwf indf0 erase_block movlw code_addr_upper ; load tblptr with the base movwf tblptru ; address of the memory block movlw code_addr_high movwf tblptrh movlw code_addr_low movwf tblptrl bsf eecon1, eepgd ; point to flash program memory bcf eecon1, cfgs ; access flash program memory bsf eecon1, wren ; enable write to memory bsf eecon1, free ; enable row erase operation bcf intcon, gie ; disable interrupts movlw 55h required movwf eecon2 ; write 55h sequence movlw 0aah movwf eecon2 ; write 0aah bsf eecon1, wr ; start erase (cpu stall) bsf intcon, gie ; re-enable interrupts tblrd*- ; dummy read decrement movlw buffer_addr_high ; point to buffer movwf fsr0h movlw buffer_addr_low movwf fsr0l write_buffer_back movlw size_of_block ; number of bytes in holding register movwf counter write_byte_to_hregs movff postinc0, wreg ; get low byte of buffer data movwf tablat ; present data to table latch tblwt+* ; write data, perform a short write ; to internal tblwt holding register. decfsz counter ; loop until buffers are full bra write_byte_to_hregs
? 2011 microchip technology inc. ds39977d-page 141 pic18f66k80 family example 7-3: writing to flash program memory (continued) 7.5.2 write verify depending on the application, good programming practice may dictate that the value written to the memory should be verified against the original value. this should be used in applications where excessive writes can stress bits near the specification limit. 7.5.3 unexpected termination of write operation if a write is terminated by an unplanned event, such as loss of power or an unexpected reset, the memory location just programmed should be verified and repro- grammed if needed. if the write operation is interrupted by a mclr reset or a wdt time-out reset during normal operation, the user can check the wrerr bit and rewrite the location(s) as needed. 7.5.4 protection against spurious writes to protect against spurious writes to flash program memory, the write initiate sequence must also be followed. see section 28.0 ?special features of the cpu? for more detail. 7.6 flash program operation during code protection see section 28.6 ?program verification and code protection? for details on code protection of flash program memory. table 7-2: registers associated with program flash memory program_memory bsf eecon1, eepgd ; point to flash program memory bcf eecon1, cfgs ; access flash program memory bsf eecon1, wren ; enable write to memory bcf intcon, gie ; disable interrupts movlw 55h required movwf eecon2 ; write 55h sequence movlw 0aah movwf eecon2 ; write 0aah bsf eecon1, wr ; start program (cpu stall) bsf intcon, gie ; re-enable interrupts bcf eecon1, wren ; disable write to memory name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 tblptru ? ?bit 21 (1) program memory table pointer upper byte (tblptr<20:16>) tbpltrh program memory table pointer high byte (tblptr<15:8>) tblptrl program memory table pointer low byte (tblptr<7:0>) tablat program memory table latch intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif eecon2 eeprom control register 2 (not a physical register) eecon1 eepgd cfgs ? free wrerr wren wr rd ipr4 tmr4ip eeip cmp2ip cmp1ip ? ccp5ip ccp4ip ccp3ip pir4 tmr4if eeif cmp2if cmp1if ? ccp5if ccp4if ccp3if pie4 tmr4ie eeie cmp2ie cmp1ie ? ccp5ie ccp4ie ccp3ie legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used during flash/eeprom access. note 1: bit 21 of the tblptru allows access to the device configuration bits.
pic18f66k80 family ds39977d-page 142 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds39977d-page 143 pic18f66k80 family 8.0 data eeprom memory the data eeprom is a nonvolatile memory array, separate from the data ram and program memory, that is used for long-term storage of program data. it is not directly mapped in either the register file or program memory space, but is indirectly addressed through the special function registers (sfrs). the eeprom is readable and writable during normal operation over the entire v dd range. five sfrs are used to read and write to the data eeprom, as well as the program memory. they are: ? eecon1 ? eecon2 ? eedata ? eeadr ? eeadrh the data eeprom allows byte read and write. when interfacing to the data memory block, eedata holds the 8-bit data for read/write and the eeadrh:eeadr register pair holds the address of the eeprom location being accessed. the eeprom data memory is rated for high erase/write cycle endurance. a byte write automatically erases the location and writes the new data (erase-before-write). the write time is controlled by an on-chip timer; it will vary with voltage and temperature, as well as from chip- to-chip. please refer to parameter d122 ( table 31-1 in section 31.0 ?electrical characteristics? ) for exact limits. 8.1 eeadr and eeadrh registers the eeadrh:eeadr register pair is used to address the data eeprom for read and write operations. eeadrh holds the two msbs of the address; the upper 6 bits are ignored. the 10-bit range of the pair can address a memory range of 1024 bytes (00h to 3ffh). 8.2 eecon1 and eecon2 registers access to the data eeprom is controlled by two registers: eecon1 and eecon2. these are the same registers which control access to the program memory and are used in a similar manner for the data eeprom. the eecon1 register ( register 8-1 ) is the control register for data and program memory access. control bit, eepgd, determines if the access will be to program memory or data eeprom memory. when clear, operations will access the data eeprom memory. when set, program memory is accessed. control bit, cfgs, determines if the access will be to the configuration registers or to program memory/data eeprom memory. when set, subsequent operations access configuration registers. when cfgs is clear, the eepgd bit selects either program flash or data eeprom memory. the wren bit, when set, will allow a write operation. on power-up, the wren bit is clear. the wrerr bit is set in hardware when the wren bit is set and cleared, when the internal programming timer expires and the write operation is complete. the wr control bit initiates write operations. the bit cannot be cleared, only set, in software; it is cleared in hardware at the completion of the write operation. control bits, rd and wr, start read and erase/write operations, respectively. these bits are set by firmware and cleared by hardware at the completion of the operation. the rd bit cannot be set when accessing program memory (eepgd = 1 ). program memory is read using table read instructions. see section 7.1 ?table reads and table writes? regarding table reads. the eecon2 register is not a physical register. it is used exclusively in the memory write and erase sequences. reading eecon2 will read all ? 0 ?s. note: during normal operation, the wrerr is read as ? 1 ?. this can indicate that a write operation was prematurely terminated by a reset, or a write operation was attempted improperly. note: the eeif interrupt flag bit (pir4<6>) is set when the write is complete. it must be cleared in software.
pic18f66k80 family ds39977d-page 144 ? 2011 microchip technology inc. register 8-1: eecon1: data eeprom control register 1 r/w-x r/w-x u-0 r/w-0 r/w-x r/w-0 r/s-0 r/s-0 eepgd cfgs ? free wrerr (1) wren wr rd bit 7 bit 0 legend: s = settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 eepgd: flash program or data eeprom memory select bit 1 = access flash program memory 0 = access data eeprom memory bit 6 cfgs: flash program/data eeprom or configuration select bit 1 = access configuration registers 0 = access flash program or data eeprom memory bit 5 unimplemented: read as ? 0 ? bit 4 free: flash row erase enable bit 1 = erase the program memory row addressed by tblptr on the next wr command (cleared by completion of erase operation) 0 = perform write only bit 3 wrerr: flash program/data eeprom error flag bit (1) 1 = a write operation is prematurely terminated (any reset during self-timed programming in normal operation or an improper write attempt) 0 = the write operation completed bit 2 wren: flash program/data eeprom write enable bit 1 = allows write cycles to flash program/data eeprom 0 = inhibits write cycles to flash program/data eeprom bit 1 wr: write control bit 1 = initiates a data eeprom erase/write cycle, or a program memory erase cycle or write cycle. (the operation is self-timed and the bit is cleared by hardware once the write is complete. the wr bit can only be set (not cleared) in software.) 0 = write cycle to the eeprom is complete bit 0 rd: read control bit 1 = initiates an eeprom read (read takes one cycle. rd is cleared in hardware. the rd bit can only be set (not cleared) in software. rd bit cannot be set when eepgd = 1 or cfgs = 1 .) 0 = does not initiate an eeprom read note 1: when a wrerr occurs, the eepgd and cfgs bits are not cleared. this allows tracing of the error condition.
? 2011 microchip technology inc. ds39977d-page 145 pic18f66k80 family 8.3 reading the data eeprom memory to read a data memory location, the user must write the address to the eeadrh:eeadr register pair, clear the eepgd control bit (eecon1<7>) and then set control bit, rd (eecon1<0>). the data is available after one instruction cycle, in the eedata register. it can be read after one nop instruction. eedata will hold this value until another read operation or until it is written to by the user (during a write operation). the basic process is shown in example 8-1 . 8.4 writing to the data eeprom memory to write an eeprom data location, the address must first be written to the eeadrh:eeadr register pair and the data written to the eedata register. the sequence in example 8-2 must be followed to initiate the write cycle. the write will not begin if this sequence is not exactly followed (write 55h to eecon2, write 0aah to eecon2, then set wr bit) for each byte. it is strongly recommended that interrupts be disabled during this code segment. additionally, the wren bit in eecon1 must be set to enable writes. this mechanism prevents accidental writes to data eeprom due to unexpected code exe- cution (i.e., runaway programs). the wren bit should be kept clear at all times, except when updating the eeprom. the wren bit is not cleared by hardware. after a write sequence has been initiated, eecon1, eeadrh:eeadr and eedata cannot be modified. the wr bit will be inhibited from being set unless the wren bit is set. the wren bit must be set on a previous instruction. both wr and wren cannot be set with the same instruction. at the completion of the write cycle, the wr bit is cleared in hardware and the eeprom interrupt flag bit (eeif) is set. the user may either enable this interrupt or poll this bit; eeif must be cleared by software. 8.5 write verify depending on the application, good programming practice may dictate that the value written to the memory should be verified against the original value. this should be used in applications where excessive writes can stress bits near the specification limit. note: self-write execution to flash and eeprom memory cannot be done while running in lp oscillator (low-power) mode. executing a self-write will put the device into high-power mode.
pic18f66k80 family ds39977d-page 146 ? 2011 microchip technology inc. example 8-1: data eeprom read example 8-2: data eeprom write movlw data_ee_addrh ; movwf eeadrh ; upper bits of data memory address to read movlw data_ee_addr ; movwf eeadr ; lower bits of data memory address to read bcf eecon1, eepgd ; point to data memory bcf eecon1, cfgs ; access eeprom bsf eecon1, rd ; eeprom read nop movf eedata, w ; w = eedata movlw data_ee_addrh ; movwf eeadrh ; upper bits of data memory address to write movlw data_ee_addr ; movwf eeadr ; lower bits of data memory address to write movlw data_ee_data ; movwf eedata ; data memory value to write bcf eecon1, eepgd ; point to data memory bcf eecon1, cfgs ; access eeprom bsf eecon1, wren ; enable writes bcf intcon, gie ; disable interrupts movlw 55h ; required movwf eecon2 ; write 55h sequence movlw 0aah ; movwf eecon2 ; write 0aah bsf eecon1, wr ; set wr bit to begin write btfsc eecon1, wr ; wait for write to complete goto $-2 bsf intcon, gie ; enable interrupts ; user code execution bcf eecon1, wren ; disable writes on write complete (eeif set)
? 2011 microchip technology inc. ds39977d-page 147 pic18f66k80 family 8.6 operation during code-protect data eeprom memory has its own code-protect bits in configuration words. external read and write operations are disabled if code protection is enabled. the microcontroller itself can both read and write to the internal data eeprom regardless of the state of the code-protect configuration bit. refer to section 28.0 ?special features of the cpu? for additional information. 8.7 protection against spurious write there are conditions when the device may not want to write to the data eeprom memory. to protect against spurious eeprom writes, various mechanisms have been implemented. on power-up, the wren bit is cleared. in addition, writes to the eeprom are blocked during the power-up timer period (t pwrt , parameter 33 ). the write initiate sequence, and the wren bit together, help prevent an accidental write during brown-out, power glitch or software malfunction. 8.8 using the data eeprom the data eeprom is a high-endurance, byte- addressable array that has been optimized for the storage of frequently changing information (e.g., pro- gram variables or other data that are updated often). frequently changing values will typically be updated more often than specification d124 . if this is not the case, an array refresh must be performed. for this reason, variables that change infrequently (such as constants, ids, calibration, etc.) should be stored in flash program memory. a simple data eeprom refresh routine is shown in example 8-3 . example 8-3: data eeprom refresh routine note: if data eeprom is only used to store constants and/or data that changes often, an array refresh is likely not required. see specification d124 . clrf eeadr ; start at address 0 clrf eeadrh ; bcf eecon1, cfgs ; set for memory bcf eecon1, eepgd ; set for data eeprom bcf intcon, gie ; disable interrupts bsf eecon1, wren ; enable writes loop ; loop to refresh array bsf eecon1, rd ; read current address movlw 55h ; movwf eecon2 ; write 55h movlw 0aah ; movwf eecon2 ; write 0aah bsf eecon1, wr ; set wr bit to begin write btfsc eecon1, wr ; wait for write to complete bra $-2 incfsz eeadr, f ; increment address bra loop ; not zero, do it again incfsz eeadrh, f ; increment the high address bra loop ; not zero, do it again bcf eecon1, wren ; disable writes bsf intcon, gie ; enable interrupts
pic18f66k80 family ds39977d-page 148 ? 2011 microchip technology inc. table 8-1: registers associated with data eeprom memory name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif eeadrh eeprom address register high byte eeadr eeprom address register low byte eedata eeprom data register eecon2 eeprom control register 2 (not a physical register) eecon1 eepgd cfgs ? free wrerr wren wr rd ipr4 tmr4ip eeip cmp2ip cmp1ip ? ccp5ip ccp4ip ccp3ip pir4 tmr4if eeif cmp2if cmp1if ? ccp5if ccp4if ccp3if pie4 tmr4ie eeie cmp2ie cmp1ie ? ccp5ie ccp4ie ccp3ie legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used during flash/eeprom access.
? 2011 microchip technology inc. ds39977d-page 149 pic18f66k80 family 9.0 8 x 8 hardware multiplier 9.1 introduction all pic18 devices include an 8 x 8 hardware multiplier as part of the alu. the multiplier performs an unsigned operation and yields a 16-bit result that is stored in the product register pair, prodh:prodl. the multiplier?s operation does not affect any flags in the status register. making multiplication a hardware operation allows it to be completed in a single instruction cycle. this has the advantages of higher computational throughput and reduced code size for multiplication algorithms and allows pic18 devices to be used in many applications previously reserved for digital-signal processors. a comparison of various hardware and software multiply operations, along with the savings in memory and execution time, is shown in ta b l e 9 - 1 . 9.2 operation example 9-1 shows the instruction sequence for an 8 x 8 unsigned multiplication. only one instruction is required when one of the arguments is already loaded in the wreg register. example 9-2 shows the sequence to do an 8 x 8 signed multiplication. to account for the sign bits of the argu- ments, each argument?s most significant bit (msb) is tested and the appropriate subtractions are done. example 9-1: 8 x 8 unsigned multiply routine example 9-2: 8 x 8 signed multiply routine table 9-1: performance comparison for v arious multiply operations movf arg1, w ; mulwf arg2 ; arg1 * arg2 -> ; prodh:prodl movf arg1, w mulwf arg2 ; arg1 * arg2 -> ; prodh:prodl btfsc arg2, sb ; test sign bit subwf prodh, f ; prodh = prodh ; - arg1 movf arg2, w btfsc arg1, sb ; test sign bit subwf prodh, f ; prodh = prodh ; - arg2 routine multiply method program memory (words) cycles (max) time @ 64 mhz @ 48 mhz @ 10 mhz @ 4 mhz 8 x 8 unsigned without hardware multiply 13 69 4.3 ? s5.7 ? s27.6 ? s69 ? s hardware multiply 1 1 62.5 ns 83.3 ns 400 ns 1 ? s 8 x 8 signed without hardware multiply 33 91 5.6 ? s7.5 ? s36.4 ? s91 ? s hardware multiply 6 6 375 ns 500 ns 2.4 ? s6 ? s 16 x 16 unsigned without hardware multiply 21 242 15.1 ? s20.1 ? s96.8 ? s 242 ? s hardware multiply 28 28 1.7 ? s2.3 ? s11.2 ? s28 ? s 16 x 16 signed without hardware multiply 52 254 15.8 ? s21.2 ? s 101.6 ? s 254 ? s hardware multiply 35 40 2.5 ? s3.3 ? s16.0 ? s40 ? s
pic18f66k80 family ds39977d-page 150 ? 2011 microchip technology inc. example 9-3 shows the sequence to do a 16 x 16 unsigned multiplication. equation 9-1 shows the algorithm that is used. the 32-bit result is stored in four registers (res3:res0). equation 9-1: 16 x 16 unsigned multiplication algorithm example 9-3: 16 x 16 unsigned multiply routine example 9-4 shows the sequence to do a 16 x 16 signed multiply. equation 9-2 shows the algorithm used. the 32-bit result is stored in four registers (res3:res0). to account for the sign bits of the arguments, the msb for each argument pair is tested and the appropriate subtractions are done. equation 9-2: 16 x 16 signed multiplication algorithm example 9-4: 16 x 16 signed multiply routine res3:res0 = arg1h:arg1l ? arg2h:arg2l = (arg1h ? arg2h ? 2 16 ) + (arg1h ? arg2l ? 2 8 ) + (arg1l ? arg2h ? 2 8 ) + (arg1l ? arg2l) movf arg1l, w mulwf arg2l ; arg1l * arg2l-> ; prodh:prodl movff prodh, res1 ; movff prodl, res0 ; ; movf arg1h, w mulwf arg2h ; arg1h * arg2h-> ; prodh:prodl movff prodh, res3 ; movff prodl, res2 ; ; movf arg1l, w mulwf arg2h ; arg1l * arg2h-> ; prodh:prodl movf prodl, w ; addwf res1, f ; add cross movf prodh, w ; products addwfc res2, f ; clrf wreg ; addwfc res3, f ; ; movf arg1h, w ; mulwf arg2l ; arg1h * arg2l-> ; prodh:prodl movf prodl, w ; addwf res1, f ; add cross movf prodh, w ; products addwfc res2, f ; clrf wreg ; addwfc res3, f ; res3:res0= arg1h:arg1l ? arg2h:arg2l = (arg1h ? arg2h ? 2 16 ) + (arg1h ? arg2l ? 2 8 ) + (arg1l ? arg2h ? 2 8 ) + (arg1l ? arg2l) + (-1 ? arg2h<7> ? arg1h:arg1l ? 2 16 ) + (-1 ? arg1h<7> ? arg2h:arg2l ? 2 16 ) movf arg1l, w mulwf arg2l ; arg1l * arg2l -> ; prodh:prodl movff prodh, res1 ; movff prodl, res0 ; ; movf arg1h, w mulwf arg2h ; arg1h * arg2h -> ; prodh:prodl movff prodh, res3 ; movff prodl, res2 ; ; movf arg1l, w mulwf arg2h ; arg1l * arg2h -> ; prodh:prodl movf prodl, w ; addwf res1, f ; add cross movf prodh, w ; products addwfc res2, f ; clrf wreg ; addwfc res3, f ; ; movf arg1h, w ; mulwf arg2l ; arg1h * arg2l -> ; prodh:prodl movf prodl, w ; addwf res1, f ; add cross movf prodh, w ; products addwfc res2, f ; clrf wreg ; addwfc res3, f ; ; btfss arg2h, 7 ; arg2h:arg2l neg? bra sign_arg1 ; no, check arg1 movf arg1l, w ; subwf res2 ; movf arg1h, w ; subwfb res3 ; sign_arg1 btfss arg1h, 7 ; arg1h:arg1l neg? bra cont_code ; no, done movf arg2l, w ; subwf res2 ; movf arg2h, w ; subwfb res3 ; cont_code :
? 2011 microchip technology inc. ds39977d-page 151 pic18f66k80 family 10.0 interrupts members of the pic18f66k80 family of devices have multiple interrupt sources and an interrupt priority feature that allows most interrupt sources to be assigned a high-priority level or a low-priority level. the high-priority interrupt vector is at 0008h and the low-priority interrupt vector is at 0018h. high-priority interrupt events will interrupt any low-priority interrupts that may be in progress. the registers for controlling interrupt operation are: ? rcon ?intcon ? intcon2 ? intcon3 ? pir1, pir2, pir3, pir4 and pir5 ? pie1, pie2, pie3, pie4 and pie5 ? ipr1, ipr2, ipr3, ipr4 and ipr5 it is recommended that the microchip header files supplied with mplab ? ide be used for the symbolic bit names in these registers. this allows the assembler/compiler to automatically take care of the placement of these bits within the specified register. in general, interrupt sources have three bits to control their operation. they are: ? flag bit ? indicating that an interrupt event occurred ? enable bit ? enabling program execution to branch to the interrupt vector address when the flag bit is set ? priority bit ? specifying high priority or low priority the interrupt priority feature is enabled by setting the ipen bit (rcon<7>). when interrupt priority is enabled, there are two bits that enable interrupts globally. setting the gieh bit (intcon<7>) enables all interrupts that have the priority bit set (high priority). setting the giel bit (intcon<6>) enables all interrupts that have the priority bit cleared (low priority). when the interrupt flag, enable bit and appropriate global interrupt enable bit are set, the interrupt will vector immediately to address 0008h or 0018h, depending on the priority bit setting. individual interrupts can be disabled through their corresponding enable bits. when the ipen bit is cleared (default state), the interrupt priority feature is disabled and interrupts are compatible with pic ? mid-range devices. in compatibility mode, the interrupt priority bits for each source have no effect. intcon<6> is the peie bit that enables/disables all peripheral interrupt sources. intcon<7> is the gie bit that enables/disables all interrupt sources. all interrupts branch to address 0008h in compatibility mode. when an interrupt is responded to, the global interrupt enable bit is cleared to disable further interrupts. if the ipen bit is cleared, this is the gie bit. if interrupt priority levels are used, this will be either the gieh or giel bit. high-priority interrupt sources can interrupt a low-priority interrupt. low-priority interrupts are not processed while high-priority interrupts are in progress. the return address is pushed onto the stack and the pc is loaded with the interrupt vector address (0008h or 0018h). once in the interrupt service routine (isr), the source(s) of the interrupt can be determined by poll- ing the interrupt flag bits. the interrupt flag bits must be cleared in software before re-enabling interrupts to avoid recursive interrupts. the ?return from interrupt? instruction, retfie , exits the interrupt routine and sets the gie bit (gieh or giel if priority levels are used) that re-enables interrupts. for external interrupt events, such as the intx pins or the portb input change interrupt, the interrupt latency will be three to four instruction cycles. the exact latency is the same for one or two-cycle instructions. individual interrupt flag bits are set regardless of the status of their corresponding enable bit or the gie bit. note: do not use the movff instruction to modify any of the interrupt control registers while any interrupt is enabled. doing so may cause erratic microcontroller behavior.
pic18f66k80 family ds39977d-page 152 ? 2011 microchip technology inc. figure 10-1: pic18f66k80 family interrupt logic tmr0ie gie/gieh peie/giel wake-up if in interrupt to cpu vector to location 0008h int2if int2ie int2ip int1if int1ie int1ip tmr0if tmr0ie tmr0ip rbif rbie rbip ipen tmr0if tmr0ip int1if int1ie int1ip int2if int2ie int2ip rbif rbie rbip int0if int0ie peie/giel interrupt to cpu vector to location ipen ipen 0018h pir1<7:0> pie1<7:0> ipr1<7:0> high-priority interrupt generation low-priority interrupt generation idle or sleep modes gie/gieh int3if int3ie int3ip int3if int3ie int3ip pir2<7,5:0> pie2<7,5:0> ipr2<7,5:0> pir3<7,5> pie3<7,5> ipr3<7,5> pir1<7:0> pie1<7:0> ipr1<7:0> pir2<7, 5:0> pie2<7, 5:0> ipr2< 7, 5:0 > pir3<7, 5:0> pie3<7, 5:0> ipr3< 7, 5:0 > ipen pir4<7:0> pie4<7:0> ipr4<7:0> pir5<7:0> pie5<7:0> ipr5<7:0> pir4<7:0> pie4<7:0> ipr4<7:0> pir5<7:0> pie5<7:0> ipr5<7:0>
? 2011 microchip technology inc. ds39977d-page 153 pic18f66k80 family 10.1 intcon registers the intcon registers are readable and writable registers that contain various enable, priority and flag bits. note: interrupt flag bits are set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global interrupt enable bit. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. this feature allows for software polling. register 10-1: intcon: interrupt control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-x gie/gieh peie/giel tmr0ie int0ie rbie (2) tmr0if int0if rbif (1) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 gie/gieh: global interrupt enable bit when ipen = 0 : 1 = enables all unmasked interrupts 0 = disables all interrupts when ipen = 1 : 1 = enables all high-priority interrupts 0 = disables all interrupts bit 6 peie/giel: peripheral interrupt enable bit when ipen = 0 : 1 = enables all unmasked peripheral interrupts 0 = disables all peripheral interrupts when ipen = 1 : 1 = enables all low-priority peripheral interrupts 0 = disables all low-priority peripheral interrupts bit 5 tmr0ie: tmr0 overflow interrupt enable bit 1 = enables the tmr0 overflow interrupt 0 = disables the tmr0 overflow interrupt bit 4 int0ie: int0 external interrupt enable bit 1 = enables the int0 external interrupt 0 = disables the int0 external interrupt bit 3 rbie: rb port change interrupt enable bit (2) 1 = enables the rb port change interrupt 0 = disables the rb port change interrupt bit 2 tmr0if: tmr0 overflow interrupt flag bit 1 = tmr0 register has overflowed (must be cleared in software) 0 = tmr0 register has not overflowed bit 1 int0if: int0 external interrupt flag bit 1 = the int0 external interrupt occurred (must be cleared in software) 0 = the int0 external interrupt did not occur bit 0 rbif: rb port change interrupt flag bit (1) 1 = at least one of the rb<7:4> pins changed state (must be cleared in software) 0 = none of the rb<7:4> pins have changed state note 1: a mismatch condition will continue to set this bit. to end the mismatch condition and allow the bit to be cleared, read portb and wait one additional instruction cycle. 2: each pin on portb for interrupt-on-change is individually enabled and disabled in the iocb register. by default, all pins are enabled.
pic18f66k80 family ds39977d-page 154 ? 2011 microchip technology inc. register 10-2: intcon2: in terrupt control register 2 r/w-1 r/w-1 r/w-1 r/w-1 r/w-x r/w-1 r/w-x r/w-1 rbpu intedg0 intedg1 intedg2 intedg3 tmr0ip int3ip rbip bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 rbpu : portb pull-up enable bit 1 = all portb pull-ups are disabled 0 = portb pull-ups are enabled by individual port latch values bit 6 intedg0: external interrupt 0 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 5 intedg1: external interrupt 1 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 4 intedg2: external interrupt 2 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 3 intedg3: external interrupt 3 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 2 tmr0ip: tmr0 overflow interrupt priority bit 1 =high priority 0 = low priority bit 1 int3ip: int3 external interrupt priority bit 1 =high priority 0 = low priority bit 0 rbip: rb port change interrupt priority bit 1 =high priority 0 = low priority note: interrupt flag bits are set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global interrupt enable bit. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. this feature allows for software polling.
? 2011 microchip technology inc. ds39977d-page 155 pic18f66k80 family register 10-3: intcon3: in terrupt control register 3 r/w-1 r/w-1 r/w-0 r/w-0 r/w-0 r/w-x r/w-0 r/w-0 int2ip int1ip int3ie int2ie int1ie int3if int2if int1if bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 int2ip: int2 external interrupt priority bit 1 =high priority 0 = low priority bit 6 int1ip: int1 external interrupt priority bit 1 =high priority 0 = low priority bit 5 int3ie: int3 external interrupt enable bit 1 = enables the int3 external interrupt 0 = disables the int3 external interrupt bit 4 int2ie: int2 external interrupt enable bit 1 = enables the int2 external interrupt 0 = disables the int2 external interrupt bit 3 int1ie: int1 external interrupt enable bit 1 = enables the int1 external interrupt 0 = disables the int1 external interrupt bit 2 int3if: int3 external interrupt flag bit 1 = the int3 external interrupt occurred (must be cleared in software) 0 = the int3 external interrupt did not occur bit 1 int2if: int2 external interrupt flag bit 1 = the int2 external interrupt occurred (must be cleared in software) 0 = the int2 external interrupt did not occur bit 0 int1if: int1 external interrupt flag bit 1 = the int1 external interrupt occurred (must be cleared in software) 0 = the int1 external interrupt did not occur note: interrupt flag bits are set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global interrupt enable bit. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. this feature allows for software polling.
pic18f66k80 family ds39977d-page 156 ? 2011 microchip technology inc. 10.2 pir registers the pir registers contain the individual flag bits for the peripheral interrupts. due to the number of peripheral interrupt sources, there are six peripheral interrupt request (flag) registers (pir1 through pir5). note 1: interrupt flag bits are set when an interrupt condition occurs regardless of the state of its corresponding enable bit or the global interrupt enable bit, gie (intcon<7>). 2: user software should ensure the appropriate interrupt flag bits are cleared prior to enabling an interrupt and after servicing that interrupt. register 10-4: pir1: peripheral interrupt request (flag) register 1 r/w-0 r/w-0 r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 pspif adif rc1if tx1if sspif tmr1gif tmr2if tmr1if bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 pspif: parallel slave port read/write interrupt flag bit 1 = a read or write operation has taken place (must be cleared in software) 0 = no read or write operation has occurred bit 6 adif: a/d converter interrupt flag bit 1 = an a/d conversion completed (must be cleared in software) 0 = the a/d conversion is not complete bit 5 rc1if: eusart receive interrupt flag bit 1 = the eusart receive buffer, rcreg1, is full (cleared when rcreg1 is read) 0 = the eusart receive buffer is empty bit 4 tx1if: eusart transmit interrupt flag bit 1 = the eusart transmit buffer, txreg1, is empty (cleared when txreg1 is written) 0 = the eusart transmit buffer is full bit 3 sspif: master synchronous serial port interrupt flag bit 1 = the transmission/reception is complete (must be cleared in software) 0 = waiting to transmit/receive bit 2 tmr1gif: timer1 gate interrupt flag bit 1 = timer gate interrupt occurred (must be cleared in software) 0 = no timer gate interrupt occurred bit 1 tmr2if: tmr2 to pr2 match interrupt flag bit 1 = tmr2 to pr2 match occurred (must be cleared in software) 0 = no tmr2 to pr2 match occurred bit 0 tmr1if: tmr1 overflow interrupt flag bit 1 = tmr1 register overflowed (must be cleared in software) 0 = tmr1 register did not overflow
? 2011 microchip technology inc. ds39977d-page 157 pic18f66k80 family register 10-5: pir2: peripheral interrupt request (flag) register 2 r/w-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 oscfif ? ? ? bclif hlvdif tmr3if tmr3gif bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 oscfif: oscillator fail interrupt flag bit 1 = device oscillator failed, clock input has changed to intosc (bit must be cleared in software) 0 = device clock operating bit 6-4 unimplemented: read as ?0? bit 3 bclif: bus collision interrupt flag bit 1 = a bus collision occurred (bit must be cleared in software) 0 = no bus collision occurred bit 2 hlvdif: high/low-voltage detect interrupt flag bit 1 = a low-voltage condition occurred (bit must be cleared in software) 0 = the device voltage is above the regulator?s low-voltage trip point bit 1 tmr3if: tmr3 overflow interrupt flag bit 1 = tmr3 register overflowed (bit must be cleared in software) 0 = tmr3 register did not overflow bit 0 tmr3gif: tmr3 gate interrupt flag bit 1 = timer gate interrupt occurred (bit must be cleared in software) 0 = no timer gate interrupt occurred
pic18f66k80 family ds39977d-page 158 ? 2011 microchip technology inc. register 10-6: pir3: peripheral interrupt request (flag) register 3 u-0 u-0 r-0 r-0 r/w-0 r/w-0 r/w-0 u-0 ? ? rc2if tx2if ctmuif ccp2if ccp1if ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5 rc2if: eusart receive interrupt flag bit 1 = the eusart receive buffer, rcreg2, is full (cleared when rcreg2 is read) 0 = the eusart receive buffer is empty bit 4 tx2if: eusart transmit interrupt flag bit 1 = the eusart transmit buffer, txreg2, is empty (cleared when txreg2 is written) 0 = the eusart transmit buffer is full bit 3 ctmuif: ctmu interrupt flag bit 1 = ctmu interrupt occurred (must be cleared in software) 0 = no ctmu interrupt occurred bit 2 ccp2if: ccp2 interrupt flag bit capture mode: 1 = a tmr1/tmr3 register capture occurred (must be cleared in software) 0 = no tmr1/tmr3 register capture occurred compare mode: 1 = a tmr1/tmr3 register compare match occurred (must be cleared in software) 0 = no tmr1/tmr3 register compare match occurred pwm mode: unused in this mode. bit 1 ccp1if: eccp1 interrupt flag bit capture mode: 1 = a tmr1/tmr3 register capture occurred (must be cleared in software) 0 = no tmr1/tmr3 register capture occurred compare mode: 1 = a tmr1/tmr3 register compare match occurred (must be cleared in software) 0 = no tmr1/tmr3 register compare match occurred pwm mode: unused in this mode. bit 0 unimplemented: read as ? 0 ?
? 2011 microchip technology inc. ds39977d-page 159 pic18f66k80 family register 10-7: pir4: peripheral interrupt request (flag) register 4 r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 tmr4if eeif cmp2if cmp1if ? ccp5if ccp4if ccp3if bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 tmr4if: tmr4 overflow interrupt flag bit 1 = tmr4 register overflowed (must be cleared in software) 0 = tmr4 register did not overflow bit 6 eeif: data eedata/flash write operation interrupt flag bit 1 = the write operation is complete (must be cleared in software) 0 = the write operation is not complete or has not been started bit 5 cmp2if: cmp2 interrupt flag bit 1 = cmp2 interrupt occurred (must be cleared in software) 0 = cmp2 interrupt did not occur bit 4 cmp1if: cmp1 interrupt flag bit 1 = cmp1 interrupt occurred (must be cleared in software) 0 = cmp1 interrupt did not occur bit 3 unimplemented: read as ? 0 ? bit 2 ccp5if: ccp5 interrupt flag bit capture mode 1 = a tmr register capture occurred (bit must be cleared in software) 0 = no tmr register capture occurred compare mode 1 = a tmr register compare match occurred (must be cleared in software) 0 = no tmr register compare match occurred pwm mode not used in pwm mode. bit 1 ccp4if: ccp4 interrupt flag bit capture mode 1 = a tmr register capture occurred (bit must be cleared in software) 0 = no tmr register capture occurred compare mode 1 = a tmr register compare match occurred (must be cleared in software) 0 = no tmr register compare match occurred pwm mode not used in pwm mode. bit 0 ccp3if: ccp3 interrupt flag bit capture mode 1 = a tmr register capture occurred (bit must be cleared in software) 0 = no tmr register capture occurred compare mode 1 = a tmr register compare match occurred (must be cleared in software) 0 = no tmr register compare match occurred pwm mode not used in pwm mode.
pic18f66k80 family ds39977d-page 160 ? 2011 microchip technology inc. register 10-8: pir5: peripheral interrupt request (flag) register 5 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 irxif wakif errif txb2if txb1if txb0if rxb1if rxb0if/ fifofif bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 irxif: invalid message received interrupt flag bits 1 = an invalid message occurred on the can bus 0 = no invalid message occurred on the can bus bit 6 wakif: bus wake up activity interrupt flag bit 1 = activity on can bus has occurred 0 = no activity on can bus bit 5 errif: error interrupt flag bit (multiple sources in comstat register) 1 = an error has occurred in the can module (multiple sources) 0 = no can module errors bit 4 txb2if: transmit buffer 2 interrupt flag bit 1 = transmit buffer 2 has completed transmission of a message and may be reloaded 0 = transmit buffer 2 has not completed transmission of a message bit 3 txb1if: transmit buffer 1 interrupt flag bit 1 = transmit buffer 1 has completed transmission of a message and may be reloaded 0 = transmit buffer 1 has not completed transmission of a message bit 2 txb0if: transmit buffer 0 interrupt flag bit 1 = transmit buffer 0 has completed transmission of a message and may be reloaded 0 = transmit buffer 0 has not completed transmission of a message bit 1 rxb1if: receive buffer 1 interrupt flag bit mode 0: 1 = can receive buffer 1 has received a new message 0 = can receive buffer 1 has not received a new message modes 1 and 2: 1 = a can receive buffer/fifo has received a new message 0 = a can receive buffer/fifo has not received a new message bit 0 bit operation is dependent on selected mode: mode 0: rxb0if: receive buffer 0 interrupt flag bit 1 = can receive buffer 0 has received a new message 0 = can receive buffer 0 has not received a new message mode 1: unimplemented: read as ? 0 ? mode 2: fifofif: fifo full interrupt flag bit 1 = fifo has reached full status as defined by the fifo_hf bit 0 = fifo has not reached full status as defined by the fifo_hf bit
? 2011 microchip technology inc. ds39977d-page 161 pic18f66k80 family 10.3 pie registers the pie registers contain the individual enable bits for the peripheral interrupts. due to the number of peripheral interrupt sources, there are six peripheral interrupt enable registers (pie1 through pie6). when ipen (rcon<7>) = 0 , the peie bit must be set to enable any of these peripheral interrupts. register 10-9: pie1: peripheral interrupt enable register 1 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 pspie adie rc1ie tx1ie sspie tmr1gie tmr2ie tmr1ie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 pspie: parallel slave port read/write interrupt enable bit 1 = enables the psp read/write interrupt 0 = disables the psp read/write interrupt bit 6 adie: a/d converter interrupt enable bit 1 = enables the a/d interrupt 0 = disables the a/d interrupt bit 5 rc1ie: eusart receive interrupt enable bit 1 = enables the eusart receive interrupt 0 = disables the eusart receive interrupt bit 4 tx1ie: eusart transmit interrupt enable bit 1 = enables the eusart transmit interrupt 0 = disables the eusart transmit interrupt bit 3 sspie: master synchronous serial port interrupt enable bit 1 = enables the mssp interrupt 0 = disables the mssp interrupt bit 2 tmr1gie: tmr1 gate interrupt enable bit 1 = enables the gate 0 = disabled the gate bit 1 tmr2ie: tmr2 to pr2 match interrupt enable bit 1 = enables the tmr2 to pr2 match interrupt 0 = disables the tmr2 to pr2 match interrupt bit 0 tmr1ie: tmr1 overflow interrupt enable bit 1 = enables the tmr1 overflow interrupt 0 = disables the tmr1 overflow interrupt
pic18f66k80 family ds39977d-page 162 ? 2011 microchip technology inc. register 10-10: pie2: peripheral interrupt enable register 2 r/w-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 oscfie ? ? ? bclie hlvdie tmr3ie tmr3gie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 oscfie: oscillator fail interrupt enable bit 1 = enabled 0 = disabled bit 6-4 unimplemented: read as ? 0 ? bit 3 bclie: bus collision interrupt enable bit 1 = enabled 0 = disabled bit 2 hlvdie: high/low-voltage detect interrupt enable bit 1 = enabled 0 = disabled bit 1 tmr3ie: tmr3 overflow interrupt enable bit 1 = enabled 0 = disabled bit 0 tmr3gie: timer3 gate interrupt enable bit 1 = enabled 0 = disabled
? 2011 microchip technology inc. ds39977d-page 163 pic18f66k80 family register 10-11: pie3: peripheral interrupt enable register 3 u-0 u-0 r-0 r-0 r/w-0 r/w-0 r/w-0 u-0 ? ? rc2ie tx2ie ctmuie ccp2ie ccp1ie ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5 rc2ie: eusart receive interrupt enable bit 1 = enabled 0 = disabled bit 4 tx2ie: eusart transmit interrupt enable bit 1 = enabled 0 = disabled bit 3 ctmuie: ctmu interrupt enable bit 1 = enabled 0 = disabled bit 2 ccp2ie: ccp2 interrupt enable bit 1 = enabled 0 = disabled bit 1 ccp1ie: eccp1 interrupt enable bit 1 = enabled 0 = disabled bit 0 unimplemented: read as ? 0 ?
pic18f66k80 family ds39977d-page 164 ? 2011 microchip technology inc. register 10-12: pie4: peripheral interrupt enable register 4 r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 tmr4ie eeie cmp2ie cmp1ie ? ccp5ie ccp4ie ccp3ie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 tmr4ie: tmr4 overflow interrupt flag bit 1 = interrupt enabled 0 = interrupt disabled bit 6 eeie: data eedata/flash write operation interrupt flag bit 1 = interrupt enabled 0 = interrupt disabled bit 5 cmp2ie: cmp2 interrupt flag bit 1 = interrupt enabled 0 = interrupt disabled bit 4 cmp1ie: cmp1 interrupt flag bit 1 = interrupt enabled 0 = interrupt disabled bit 3 unimplemented: read as ? 0 ? bit 2 ccp5ie: ccp5 interrupt flag bit 1 = interrupt enabled 0 = interrupt disabled bit 1 ccp4ie: ccp4 interrupt flag bit 1 = interrupt enabled 0 = interrupt disabled bit 0 ccp3ie: ccp3 interrupt flag bits 1 = interrupt enabled 0 = interrupt disabled
? 2011 microchip technology inc. ds39977d-page 165 pic18f66k80 family register 10-13: pie5: peripheral interrupt enable register 5 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 irxie wakie errie txb2ie txb1ie txb0ie rxb1ie rxb0ie/ fifofie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 irxie: invalid message received interrupt flag bit 1 = interrupt enabled 0 = interrupt disabled bit 6 wakie: bus wake up activity interrupt flag bit 1 = interrupt enabled 0 = interrupt disabled bit 5 errie: error interrupt flag bit (multiple sources in the comstat register) 1 = interrupt enabled 0 = interrupt disabled bit 4 txb2ie: transmit buffer 2 interrupt flag bit 1 = interrupt enabled 0 = interrupt disabled bit 3 txb1ie: transmit buffer 1 interrupt flag bit 1 = interrupt enabled 0 = interrupt disabled bit 2 txb0ie: transmit buffer 0 interrupt flag bit 1 = interrupt enabled 0 = interrupt disabled bit 1 rxb1ie: receive buffer 1 interrupt flag bit 1 = interrupt enabled 0 = interrupt disabled bit 0 bit operation is dependent on selected mode: mode 0: rxb0ie: receive buffer 0 interrupt flag bit 1 = interrupt enabled 0 = interrupt disabled mode 1: unimplemented: read as ? 0 ? mode 2: fifofie: fifo full interrupt flag bit 1 = interrupt enabled 0 = interrupt disabled
pic18f66k80 family ds39977d-page 166 ? 2011 microchip technology inc. 10.4 ipr registers the ipr registers contain the individual priority bits for the peripheral interrupts. due to the number of peripheral interrupt sources, there are six peripheral interrupt priority registers (ipr1 through ipr6). using the priority bits requires that the interrupt priority enable (ipen) bit (rcon<7>) be set. register 10-14: ipr1: peripheral interrupt priority register 1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 pspip adip rc1ip tx1ip sspip tmr1gip tmr2ip tmr1ip bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 pspip: parallel slave port read/write interrupt priority bit 1 =high priority 0 = low priority bit 6 adip: a/d converter interrupt priority bit 1 =high priority 0 = low priority bit 5 rc1ip: eusart receive interrupt priority bit 1 =high priority 0 = low priority bit 4 tx1ip: eusart transmit interrupt priority bit 1 =high priority 0 = low priority bit 3 sspip: master synchronous serial port interrupt priority bit 1 =high priority 0 = low priority bit 2 tmr1gip: timer1 gate interrupt priority bit 1 =high priority 0 = low priority bit 1 tmr2ip: tmr2 to pr2 match interrupt priority bit 1 =high priority 0 = low priority bit 0 tmr1ip: tmr1 overflow interrupt priority bit 1 =high priority 0 = low priority
? 2011 microchip technology inc. ds39977d-page 167 pic18f66k80 family register 10-15: ipr2: peripheral interrupt priority register 2 r/w-1 u-0 u-0 u-0 r/w-1 r/w-1 r/w-1 r/w-1 oscfip ? ? ? bclip hlvdip tmr3ip tmr3gip bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 oscfip: oscillator fail interrupt priority bit 1 =high priority 0 = low priority bit 6-4 unimplemented: read as ? 0 ? bit 3 bclip: bus collision interrupt priority bit 1 =high priority 0 = low priority bit 2 hlvdip: high/low-voltage detect interrupt priority bit 1 =high priority 0 = low priority bit 1 tmr3ip: tmr3 overflow interrupt priority bit 1 =high priority 0 = low priority bit 0 tmr3gip: tmr3 gate interrupt priority bit 1 =high priority 0 = low priority
pic18f66k80 family ds39977d-page 168 ? 2011 microchip technology inc. register 10-16: ipr3: peripheral interrupt priority register 3 u-0 u-0 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 u-0 ? ? rc2ip tx2ip ctmuip ccp2ip ccp1ip ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5 rc2ip: eusart receive priority flag bit 1 =high priority 0 = low priority bit 4 tx2ip: eusart transmit interrupt priority bit 1 =high priority 0 = low priority bit 3 ctmuip: ctmu interrupt priority bit 1 =high priority 0 = low priority bit 2 ccp2ip: ccp2 interrupt priority bit 1 =high priority 0 = low priority bit 1 ccp1ip: eccp1 interrupt priority bit 1 =high priority 0 = low priority bit 0 unimplemented: read as ? 0 ?
? 2011 microchip technology inc. ds39977d-page 169 pic18f66k80 family register 10-17: ipr4: peripheral interrupt priority register 4 r/w-1 r/w-1 r/w-1 r/w-1 u-0 r/w-1 r/w-1 r/w-1 tmr4ip eeip cmp2ip cmp1ip ? ccp5ip ccp4ip ccp3ip bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 tmr4ip: tmr4 overflow interrupt priority bit 1 = high priority 0 = low priority bit 6 eeip: ee interrupt priority bit 1 = high priority 0 = low priority bit 5 cmp2ip: cmp2 interrupt priority bit 1 = high priority 0 = low priority bit 4 cmp1ip: cmp1 interrupt priority bit 1 = high priority 0 = low priority bit 3 unimplemented: read as ? 0 ? bit 2 ccp5ip: ccp5 interrupt priority bit 1 = high priority 0 = low priority bit 1 ccp4ip: ccp4 interrupt priority bit 1 = high priority 0 = low priority bit ccp3ip: ccp3 interrupt priority bits 1 = high priority 0 = low priority
pic18f66k80 family ds39977d-page 170 ? 2011 microchip technology inc. register 10-18: ipr5: peripheral interrupt priority register 5 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 irxip wakip errip txb2ip txb1ip txb0ip rxb1ip rxb0ip/ fifofie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 irxip: invalid message received interrupt priority bits 1 = high priority 0 = low priority bit 6 wakip: bus wake up activity interrupt priority bit 1 = high priority 0 = low priority bit 5 errip: can bus error interrupt priority bit 1 = high priority 0 = low priority bit 4 txb2ip: transmit buffer 2 interrupt priority bit 1 = high priority 0 = low priority bit 3 txb1ip: transmit buffer 1 interrupt priority bit 1 = high priority 0 = low priority bit 2 txb0ip: transmit buffer 0 interrupt priority bit 1 = high priority 0 = low priority bit 1 rxb1ip: receive buffer 1 interrupt priority bit mode 0: 1 = high priority for receive buffer 1 0 = low priority for receive buffer 1 modes 1 and 2: 1 = high priority for received messages 0 = low priority for received messages bit 0 rxb0ip/fifofip: receive buffer 0 interrupt priority bit mode 0: 1 = high priority for receive buffer 0 0 = low priority for receive buffer 0 mode 1: unimplemented: read as ? 0 ? mode 2: fifofie: fifo full interrupt flag bit 1 = high priority 0 = low priority
? 2011 microchip technology inc. ds39977d-page 171 pic18f66k80 family 10.5 rcon register the rcon register contains bits used to determine the cause of the last reset or wake-up from idle or sleep modes. rcon also contains the bit that enables interrupt priorities (ipen). register 10-19: rcon: reset control register r/w-0 r/w-1 r/w-1 r/w-1 r-1 r-1 r/w-0 r/w-0 ipen sboren cm ri to pd por bor bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ipen: interrupt priority enable bit 1 = enable priority levels on interrupts 0 = disable priority levels on interrupts (pic16cxxx compatibility mode) bit 6 sboren: software bor enable bit for details of bit operation, see register 5-1 . bit 5 cm : configuration mismatch flag bit 1 = a configuration mismatch reset has not occurred 0 = a configuration mismatch reset has occurred (must be subsequently set in software) bit 4 ri : reset instruction flag bit for details of bit operation, see register 5-1 . bit 3 to : watchdog timer time-out flag bit for details of bit operation, see register 5-1 . bit 2 pd : power-down detection flag bit for details of bit operation, see register 5-1 . bit 1 por : power-on reset status bit for details of bit operation, see register 5-1 . bit 0 bor : brown-out reset status bit for details of bit operation, see register 5-1 .
pic18f66k80 family ds39977d-page 172 ? 2011 microchip technology inc. 10.6 intx pin interrupts external interrupts on the rb0/int0, rb1/int1, rb2/int2 and rb3/int3 pins are edge-triggered. if the corresponding intedgx bit in the intcon2 register is set (= 1 ), the interrupt is triggered by a rising edge. if that bit is clear, the trigger is on the falling edge. when a valid edge appears on the rbx/intx pin, the corresponding flag bit, intxif, is set. this interrupt can be disabled by clearing the corresponding enable bit, intxie. before re-enabling the interrupt, the flag bit (intxif) must be cleared in software in the interrupt service routine. all external interrupts (int0, int1, int2 and int3) can wake up the processor from the power-managed modes, if bit, intxie, was set prior to going into the power-managed modes. if the global interrupt enable bit (gie) is set, the processor will branch to the interrupt vector following wake-up. the interrupt priority for int1, int2 and int3 is determined by the value contained in the interrupt priority bits, int1ip (intcon3<6>), int2ip (intcon3<7>) and int3ip (intcon2<1>). there is no priority bit associated with int0. it is always a high-priority interrupt source. 10.7 tmr0 interrupt in 8-bit mode (the default), an overflow in the tmr0 register (ffh ? 00h) will set flag bit, tmr0if. in 16-bit mode, an overflow in the tmr0h:tmr0l register pair (ffffh ? 0000h) will set tmr0if. the interrupt can be enabled/disabled by setting/clearing enable bit, tmr0ie (intcon<5>). interrupt priority for timer0 is determined by the value contained in the inter- rupt priority bit, tmr0ip (intcon2<2>). for further details on the timer0 module, see section 13.0 ?timer0 module? . 10.8 portb interrupt-on-change an input change on portb<7:4> sets flag bit, rbif (intcon<0>). the interrupt can be enabled/disabled by setting/clearing enable bit, rbie (intcon<3>), and each individual pin can be enabled/disabled by its corresponding bit in the iocb register. interrupt priority for portb interrupt-on-change is determined by the value contained in the interrupt priority bit, rbip (intcon2<0>). register 10-20: iocb: interrupt- on-change portb control register r/w-0 r/w-0 r/w-0 r/w-0 u-0 u-0 u-0 u-0 iocb7 (1) iocb6 (1) iocb5 (1) iocb4 (1) ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 iocb<7:4>: interrupt-on-change portb control bits (1) 1 = interrupt-on-change enabled 0 = interrupt-on-change disabled bit 3-0 unimplemented: read as ? 0 ? note 1: interrupt-on-change also requires that the rbie bit of the intcon register be set.
? 2011 microchip technology inc. ds39977d-page 173 pic18f66k80 family 10.9 context saving during interrupts during interrupts, the return pc address is saved on the stack. additionally, the wreg, status and bsr registers are saved on the fast return stack. if a fast return from interrupt is not used (see section 6.3 ?data memory organization? ), the user may need to save the wreg, status and bsr regis- ters on entry to the interrupt service routine (isr). depending on the user?s application, other registers also may need to be saved. example 10-1 saves and restores the wreg, status and bsr registers during an interrupt service routine. example 10-1: saving status, wreg and bsr registers in ram table 10-1: summary of registers associated with interrupts name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif intcon2 rbpu intedg0 intedg1 intedg2 intedg3 tmr0ip int3ip rbip intcon3 int2ip int1ip int3ie int2ie int1ie int3if int2if int1if pir1 pspip adif rc1if tx1if sspif tmr1gif tmr2if tmr1if pir2 oscfif ? ? ? bclif hlvdif tmr3if tmr3gif pir3 ? ? rc2if tx2if ctmuif ccp2if ccp1if ? pir4 tmr4if eeif cmp2if cmp1if ? ccp5if ccp4if ccp3if pir5 irxif wakif errif txb2if txb1if txb0if rxb1if rxb0if pie1 pspie adie rc1ie tx1ie sspie tmr1gie tmr2ie tmr1ie pie2 oscfie ? ? ? bclie hlvdie tmr3ie tmr3gie pie3 ? ? rc2ie tx2ie ctmuie ccp2ie ccp1ie ? pie4 tmr4ie eeie ccp2ie cmp1ie ? ccp5ie ccp4ie ccp3ie pie5 irxie wakie errie txb2ie txb1ie txb0ie rxb1ie rxb0ie ipr1 pspip adip rc1ip tx1ip sspip tmr1gip tmr2ip tmr1ip ipr2 oscfip ? ? ? bclip hlvdip tmr3ip tmr3gip ipr3 ? ? rc2ip tx2ip ctmuip ccp2ip ccp1ip ? ipr4 tmr4ip eeip cmp2ip cmp1ip ? ccp5ip ccp4ip ccp3ip ipr5 irxip wakip errip txb2ip txb1ip txb0ip rxb1ip rxb0ip rcon ipen sboren cm ri to pd por bor legend: shaded cells are not used by the interrupts. movwf w_temp ; w_temp is in virtual bank movff status, status_temp ; status_temp located anywhere movff bsr, bsr_temp ; bsr_tmep located anywhere ; ; user isr code ; movff bsr_temp, bsr ; restore bsr movf w_temp, w ; restore wreg movff status_temp, status ; restore status
pic18f66k80 family ds39977d-page 174 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds39977d-page 175 pic18f66k80 family 11.0 i/o ports depending on the device selected and features enabled, there are up to seven ports available. some pins of the i/o ports are multiplexed with an alternate function from the peripheral features on the device. in general, when a peripheral is enabled, that pin may not be used as a general purpose i/o pin. each port has three memory mapped registers for its operation: ? tris register (data direction register) ? port register (reads the levels on the pins of the device) ? lat register (output latch register) reading the port register reads the current status of the pins, whereas writing to the port register, writes to the output latch (lat) register. setting a tris bit (= 1 ) makes the corresponding port pin an input (putting the corresponding output driver in a high-impedance mode). clearing a tris bit (= 0 ) makes the corresponding port pin an output (i.e., put the contents of the corresponding lat bit on the selected pin). the output latch (lat register) is useful for read-modify-write operations on the value that the i/o pins are driving. read-modify-write operations on the lat register read and write the latched output value for the port register. a simplified model of a generic i/o port, without the interfaces to other peripherals, is shown in figure 11-1 . figure 11-1: generic i/o port operation 11.1 i/o port pin capabilities when developing an application, the capabilities of the port pins must be considered. outputs on some pins have higher output drive strength than others. similarly, some pins can tolerate higher than v dd input levels. all of the digital ports are 5.5v input tolerant. the analog ports have the same tolerance, having clamping diodes implemented internally. 11.1.1 pin output drive when used as digital i/o, the output pin drive strengths vary, according to the pins? grouping to meet the needs for a variety of applications. in general, there are two classes of output pins, in terms of drive capability: ? outputs designed to drive higher current loads such as leds: -porta ? portb -portc ? outputs with lower drive levels, but capable of driving normal digital circuit loads with a high input impedance. able to drive leds, but only those with smaller current requirements: -portd (1) ?porte (1) -portf (2) ?portg (2) for more details, see ?absolute maximum ratings? in section 31.0 ?electrical characteristics? . 11.1.2 pull-up configuration five of the i/o ports (portb, portd, porte, portf and portg) implement configurable weak pull-ups on all pins. these are internal pull-ups that allow floating digital input signals to be pulled to a consistent level without the use of external resistors. the pull-ups are enabled with a single bit for each of the ports: rbpu (intcon2<7>) for portb, and rdpu, repu, rfpu and rgpu (padcfg1<7:4>) for the other ports. additionally, the portb pull-up resistors can be enabled individually using the wpub register. each bit in the register corresponds to a bit on portb. data bus wr lat wr tris rd port data latch tris latch rd tris input buffer i/o pin (1) q d ckx q d ckx en qd en rd lat or port note 1: i/o pins have diode protection to v dd and v ss . note 1: these ports are not available on 28-pin devices. 2: these ports are not available on 28-pin or 40/44-pin devices
pic18f66k80 family ds39977d-page 176 ? 2011 microchip technology inc. register 11-1: padcfg1: pad configuration register r/w-0 r/w-0 r/w-0 r/w-0 u-0 u-0 u-0 r/w-0 rdpu (1) repu (1) rfpu (2) rgpu (2) ? ? ? ctmuds bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 rdpu: portd pull-up enable bit (1) 1 = portd pull-up resistors are enabled by individual port latch values 0 = all portd pull-up resistors are disabled bit 6 repu: porte pull-up enable bit (1) 1 = porte pull-up resistors are enabled by individual port latch values 0 = all porte pull-up resistors are disabled bit 5 rfpu: portf pull-up enable bit (2) 1 = portf pull-up resistors are enabled by individual port latch values 0 = all portf pull-up resistors are disabled bit 4 rgpu: portg pull-up enable bit (2) 1 = portg pull-up resistors are enabled by individual port latch values 0 = all portg pull-up resistors are disabled bit 3-1 unimplemented: read as ? 0 ? bit 0 ctmuds: ctmu comparator data select bit 1 = external comparator (with output on pin ctdin) is used for ctmu compares 0 = internal comparator (cmp2) is used for ctmu compares note 1: unimplemented on 28-pin devices. 2: unimplemented on 40-pin devices. register 11-2: wpub: weak pull-up portb enable register r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 wpub7 wpub6 wpub5 wpub4 wpub3 wpub2 wpub1 wpub0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 wpub<7:0>: weak pull-up enable register bits 1 = pull-up enabled on corresponding portb pin when rbpu = 0 and the pin is an input 0 = pull-up disabled on corresponding portb pin
? 2011 microchip technology inc. ds39977d-page 177 pic18f66k80 family 11.1.3 open-drain outputs the output pins for several peripherals are also equipped with a configurable, open-drain output option. this allows the peripherals to communicate with external digital logic, operating at a higher voltage level, without the use of level translators. the open-drain option is implemented on port pins specifically associated with the data and clock outputs of the usarts, the mssp module (in spi mode) and the ccp modules. this option is selectively enabled by setting the open-drain control bits in the odcon register. when the open-drain option is required, the output pin must also be tied through an external pull-up resistor provided by the user to a higher voltage level, up to 5v ( figure 11-2 ). when a digital logic high signal is output, it is pulled up to the higher voltage level. figure 11-2: using the open-drain output (usart shown as example) tx x +5v 3.3v (at logic ? 1 ?) 3.3v v dd 5v pic18f66k80 register 11-3: odcon: peripher al open-drain control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 sspod ccp5od ccp4od ccp3od ccp2od ccp1od u2od u1od bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 sspod: spi open-drain output enable bit 1 = open-drain capability enabled 0 = open-drain capability disabled bit 6 ccp5od: ccp5 open-drain output enable bit 1 = open-drain capability enabled 0 = open-drain capability disabled bit 5 ccp4od: ccp4 open-drain output enable bit 1 = open-drain capability enabled 0 = open-drain capability disabled bit 4 ccp3od: ccp3 open-drain output enable bit 1 = open-drain capability enabled 0 = open-drain capability disabled bit 3 ccp2od: ccp2 open-drain output enable bit 1 = open-drain capability enabled 0 = open-drain capability disabled bit 2 ccp1od: ccp1 open-drain output enable bit 1 = open-drain capability enabled 0 = open-drain capability disabled bit 1 u2od: uart2 open-drain output enable bit 1 = open-drain capability enabled 0 = open-drain capability disabled bit 0 u1od: uart1 open-drain output enable bit 1 = open-drain capability enabled 0 = open-drain capability disabled
pic18f66k80 family ds39977d-page 178 ? 2011 microchip technology inc. 11.1.4 analog and digital ports many of the ports multiplex analog and digital function- ality, providing a lot of flexibility for hardware designers. pic18f66k80 family devices can make any analog pin analog or digital, depending on an application?s needs. the ports? analog/digital functionality is controlled by the registers: ancon0 and ancon1. setting these registers makes the corresponding pins analog and clearing the registers makes the ports digi- tal. for details on these registers, see section 23.0 ?12-bit analog-to-digital converter (a/d) module? 11.1.5 port slew rate the output slew rate of each port is programmable to select either the standard transition rate, or a reduced transition rate of ten percent of the standard transition time, to minimize emi. the reduced transition time is the default slew rate for all ports. register 11-4: slrcon: sl ew rate control register u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ?slrg (1) slrf (1) slre (2) slrd (2) slrc (2) slrb slra bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 slrg: portg slew rate control bit (1) 1 = all output pins on portg slew at 0.1 the standard rate 0 = all output pins on portg slew at standard rate bit 5 slrf: portf slew rate control bit (1) 1 = all output pins on portf slew at 0.1 the standard rate 0 = rall output pins on portf slew at standard rate bit 4 slre: porte slew rate control bit (2) 1 = all output pins on porte slew at 0.1 the standard rate 0 = all output pins on porte slew at standard rate bit 3 slrd: portd slew rate control bit (2) 1 = all output pins on portd slew at 0.1 the standard rate 0 = all output pins on portd slew at standard rate bit 2 slrc: portc slew rate control bit (2) 1 = all output pins on portc slew at 0.1 the standard rate 0 = all output pins on portc slew at standard rate bit 1 slrb: portb slew rate control bit 1 = all output pins on portb slew at 0.1 the standard rate 0 = all output pins on portb slew at standard rate bit 0 slra: porta slew rate control bit 1 = all output pins on porta slew at 0.1 the standard rate 0 = all output pins on porta slew at standard rate note 1: unimplemented and read back as ? 0 ? on 28-pin and 40/44-pin devices. 2: unimplemented and read back as ? 0 ? on 28-pin devices.
? 2011 microchip technology inc. ds39977d-page 179 pic18f66k80 family 11.2 porta, trisa and lata registers porta is a seven-bit wide, bidirectional port. the cor- responding data direction and output latch registers are trisa and lata. ra5 and ra<3:0> are multiplexed with analog inputs for the a/d converter. the operation of the analog inputs as a/d converter inputs is selected by clearing or setting the ansel control bits in the ancon1 register. the corresponding trisa bits control the direction of these pins, even when they are being used as analog inputs. the user must ensure the bits in the trisa register are maintained set when using them as analog inputs. osc2/clko/ra6 and osc1/clki/ra7 normally serve as the external circuit connections for the exter- nal (primary) oscillator circuit (hs oscillator modes) or the external clock input and output (ec oscillator modes). in these cases, ra6 and ra7 are not available as digital i/o and their corresponding tris and lat bits are read as ? 0 ?. when the device is configured to use hf-intosc, mf-intosc or lf-intosc as the default oscillator mode, ra6 and ra7 are automatically configured as digital i/o; the oscillator and clock in/clock out functions are disabled. ra5 has additional functionality for timer1 and timer3. it can be configured as the timer1 clock input or the timer3 external clock gate input. example 11-1: initializing porta note: ra5 and ra<3:0> are configured as analog inputs on any reset and are read as ? 0 ?. clrf porta ; initialize porta by ; clearing output latches clrf lata ; alternate method to ; clear output data latches movlw 00h ; configure a/d movwf ancon1 ; for digital inputs movlw 0bfh ; value used to initialize ; data direction movwf trisa ; set ra<7, 5:0> as inputs, ; ra<6> as output
pic18f66k80 family ds39977d-page 180 ? 2011 microchip technology inc. table 11-1: porta functions pin name function tris setting i/o i/o type description ra0/cv ref /an0/ ulpwu ra0 0 o dig lata<0> data output; not affected by analog input. 1 i st porta<0> data input; disabled when analog input is enabled. cv ref x o ana comparator voltage reference output . enabling this feature disables digital i/o. an0 1 i ana a/d input channel 0. default input configuration on por; does not affect digital output. ulpwu 1 o dig ultra low-power wake-up input. ra1/an1/c1inc ra1 0 o dig lata<1> data output; not affected by analog input. 1 i st porta<1> data input; disabled when analog input is enabled. an1 1 i ana a/d input channel 1. default input configuration on por; does not affect digital output. c1inc (1) x i ana comparator 1 input c. ra2/v ref -/an2/ c2inc ra2 0 o dig lata<2> data output; not affected by analog input. 1 i st porta<2> data input; disabled when analog functions are enabled. v ref - 1 i ana a/d and comparator low reference voltage input. an2 1 i ana a/d input channel 2. default input configuration on por. c2inc (1) x i ana comparator 2 input c. ra3/v ref +/an3 ra3 0 o dig lata<3> data output; not affected by analog input. 1 i st porta<3> data input; disabled when analog input is enabled. v ref + 1 i ana a/d input channel 3. default input configuration on por. an3 1 i ana a/d and comparator high reference voltage input. ra5/an4/c2inb/ hlvdin/t1cki/ss / ctmui ra5 0 o dig lata<5> data output; not affected by analog input. 1 i st porta<5> data input; disabled when analog input is enabled. an4 1 i ana a/d input channel 4. default configuration on por. c2inb (2) 1 i ana comparator 2 input b. hlvdin 1 i ana high/low-voltage detect external trip point input. t1cki x i st timer1 clock input. ss 1 i st slave select input for mssp module. ctmui (2) x o ? ctmu pulse generator charger for the c2inb comparator input. ra6/osc2/ clkout ra6 0 o dig lata<6> data output; disabled when fosc2 configuration bit is set. 1 i st porta<6> data input; disabled when fosc2 configuration bit is set. osc2 x o ana main oscillator feedback output connection (hs, xt and lp modes). clkout x o dig system cycle clock output (fosc/4) (ec and intosc modes). ra7/osc1/clkin ra7 0 o dig lata<7> data output; disabled when fosc2 configuration bit is set. 1 i st porta<7> data input; disabled when fosc2 configuration bit is set. osc1 x i ana main oscillator input connection (hs, xt, and lp modes). clkin x i ana main external clock source input (ec modes). legend: o = output, i = input, ana = analog signal, dig = cmos output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option) note 1: pin assignment unavailable for 28-pin devices (pic18f2xk80). 2: pin assignment only available fo r 28-pin devices (pic18f2xk80).
? 2011 microchip technology inc. ds39977d-page 181 pic18f66k80 family table 11-2: summary of regist ers associated with porta name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 porta ra7 (1) ra6 (1) ra5 ? ra3 ra2 ra1 ra0 lata lata7 (1) lata6 (1) lata5 ? lata3 lata2 lata1 lata0 trisa trisa7 (1) trisa6 (1) trisa5 ? trisa3 trisa2 trisa1 trisa0 ancon0 ansel7 ansel6 ansel5 ansel4 ansel3 ansel2 ansel1 ansel0 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by porta. note 1: these bits are enabled depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read as ? x ?.
pic18f66k80 family ds39977d-page 182 ? 2011 microchip technology inc. 11.3 portb, trisb and latb registers portb is an eight-bit wide, bidirectional port. the corresponding data direction and output latch registers are trisb and latb. all pins on portb are digital only. example 11-2: initializing portb each of the portb pins has a weak internal pull-up. a single control bit can turn on all the pull-ups. this is performed by clearing bit, rbpu (intcon2<7>). the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on a power-on reset. four of the portb pins (rb<7:4>) have an interrupt-on-change feature. only pins configured as inputs can cause this interrupt to occur. any rb<7:4> pins that are configured as outputs are excluded from the interrupt-on-change comparison. comparisons with the input pins (of rb<7:4>) are made with the old value latched on the last read of portb. the ?mismatch? outputs of rb<7:4> are ored together to generate the rb port change interrupt with flag bit, rbif (intcon<0>). this interrupt can wake the device from power-managed modes. to clear the interrupt in the interrupt service routine: 1. perform any read or write of portb (except with the movff (any) , portb instruction). 2. wait one instruction cycle (such as executing a nop instruction). this ends the mismatch condition. 3. clear flag bit, rbif. a mismatch condition will continue to set flag bit, rbif. reading portb will end the mismatch condition and allow flag bit, rbif, to be cleared after a one t cy delay. the interrupt-on-change feature is recommended for wake-up on key depression operation and operations where portb is only used for the interrupt-on-change feature. polling of portb is not recommended while using the interrupt-on-change feature. the rb<3:2> pins are multiplexed as ctmu edge inputs. rb5 has an additional function for timer3 and timer1. it can be configured for timer3 clock input or timer1 external clock gate input. clrf portb ; initialize portb by ; clearing output ; data latches clrf latb ; alternate method ; to clear output ; data latches movlw 0cfh ; value used to ; initialize data ; direction movwf trisb ; set rb<3:0> as inputs ; rb<5:4> as outputs ; rb<7:6> as inputs
? 2011 microchip technology inc. ds39977d-page 183 pic18f66k80 family table 11-3: portb functions pin name function tris setting i/o i/o type description rb0/an10/c1ina flt0/int0 rb0 0 o dig latb<0> data output. 1 i st portb<0> data input; weak pull-up when rbpu bit is cleared. an10 1 i ana a/d input channel 10 and comparator c1+ input. default input configuration on por. c1ina (1) 1 i ana comparator 1 input a. flt0 x i st enhanced pwm fault input for eccpx. int0 1 i st external interrupt 0 input. rb1/an8/c1inb/ p1b/ctdin/int1 rb1 0 o dig latb<1> data output. 1 i st portb<1> data input; weak pull-up when rbpu bit is cleared. an8 1 i ana a/d input channel 8 and comparator c2+ input. default input configuration on por; not affected by analog output. c1inb (1) 1 i ana comparator 1 input b. p1b (1) 0 o dig eccp1 pwm output b. may be configured for tri-state during enhanced pwm shutdown events. ctdin 1 i st ctmu pulse delay input. int1 1 i st external interrupt 1 input. rb2/cantx/c1out/ p1c/cted1/int2 rb2 0 o dig latb<2> data output. 1 i st portb<2> data input; weak pull-up when rbpu bit is cleared. cantx (2) 0 o dig can bus tx. c1out (1) 0 o dig comparator 1 output; takes priority over port data. p1c (1) 0 o dig eccp1 pwm output c. may be configured for tri-state during enhanced pwm. cted1 x i st ctmu edge 1 input. int2 1 i st external interrupt 2. rb3/canrx/ c2out/p1d/ cted2/int3 rb3 0 o dig latb<3> data output. 1 i st portb<3> data input; weak pull-up when rbpu bit is cleared. canrx (2) 1 i st can bus rx. c2out (1) x i st ctmu edge 2 input. p1d (1) 0 o dig eccp1 pwm output d. may be configured for tri-state during enhanced pwm. cted2 x i st ctmu edge 2 input. int3 1 i st external interrupt 3 input. rb4/an9/c2ina/ eccp1/p1a/ctpls/ kbi0 rb4 0 o dig latb<4> data output. 1 i st portb<4> data input; weak pull-up when rbpu bit is cleared. an9 1 i ana a/d input channel 9 and comparator c2+ input. default input configuration on por; not affected by analog output. c2ina (1) 2 i ana comparator 2 input a. eccp1 (1) 0 o dig eccp1 compare output and eccp1 pwm output. takes priority over port data. 1 i st eccp1 capture input. p1a (1) 0 o dig eccp1 enhanced pwm output, channel a. may be configured for tri-state during enhanced pwm shutdown events. takes priority over port data. ctpls x o dig ctmu pulse generator output. kbi0 1 i st interrupt-on-pin change. legend: o = output, i = input, ana = analog signal, dig = cmos output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option) note 1: pin assignment only available fo r 28-pin devices (pic18f2xk80). 2: default pin assignment for canrx and cantx when the canmx configuration bit is set. 3: default pin assignment for t0cki when the t0ckmx configuration bit is set. 4: default pin assignment for t3cki for 28, 40 and 44-pin devices . alternate pin assignment for t3cki for 64-pin devices when t3ckmx is cleared.
pic18f66k80 family ds39977d-page 184 ? 2011 microchip technology inc. table 11-4: summary of regist ers associated with portb rb5/t0cki/t3cki/ ccp5/kbi1 rb5 0 o dig latb<5> data output. 1 i st portb<5> data input; weak pull-up when rbpu bit is cleared. t0cki (3) x i st timer0 clock input. t3cki (4) x i st timer3 clock input. ccp5 0 o dig ccp5 compare/pwm output. takes priority over port data. 1 i st ccp5 capture input. kbi1 1 i st interrupt-on-pin change. rb6/pgc/tx2/ck2/ kbi2 rb6 0 o dig latb<6> data output. 1 i st portb<6> data input; weak pull-up when rbpu bit is cleared. pgc x i st serial execution (icsp?) clock input for icsp and icd operation. tx2 (1) 0 o dig asynchronous serial data output (eusart module); takes priority over port data. ck2 (1) 0 o dig synchronous serial clock out put (eusart module); user must configure as an input. 1 i st synchronous serial clock input (eusart module); user must configure as an input. kbi2 1 i st interrupt-on-pin change. rb7/pgd/t3g/rx2/ dt2/kbi3 rb7 0 o dig latb<7> data output. 1 i st portb<7> data input; weak pull-up when rbpu bit is cleared. pgd x o dig serial execution data output for icsp and icd operation. x i st serial execution data input for icsp and icd operation. t3g x i st timer3 external clock gate input. rx2 (1) 1 i st asynchronous serial receive data input (eusart module). dt2 (1) 1 o dig synchronous serial data output (ausart module); takes priority over port data. 1 i st synchronous serial data input (ausart module); user must configure as an input. kbi3 1 i st interrupt-on-pin change. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 latb latb7 latb6 latb5 latb4 latb3 latb2 latb1 latb0 trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif intcon2 rbpu intedg0 intedg1 intedg2 intedg3 tmr0ip int3ip rbip intcon3 int2ip int1ip int3ie int2ie int1ie int3if int2if int1if odcon sspod ccp5od ccp4od ccp3od ccp2od ccp1od u2od u1od ancon1 ? ansel14 ansel13 ansel12 ansel11 ansel10 ansel9 ansel8 legend: shaded cells are not used by portb. table 11-3: portb functions (continued) pin name function tris setting i/o i/o type description legend: o = output, i = input, ana = analog signal, dig = cmos output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option) note 1: pin assignment only available fo r 28-pin devices (pic18f2xk80). 2: default pin assignment for canrx and cantx when the canmx configuration bit is set. 3: default pin assignment for t0cki when the t0ckmx configuration bit is set. 4: default pin assignment for t3cki for 28, 40 and 44-pin devices . alternate pin assignment for t3cki for 64-pin devices when t3ckmx is cleared.
? 2011 microchip technology inc. ds39977d-page 185 pic18f66k80 family 11.4 portc, trisc and latc registers portc is an eight-bit wide, bidirectional port. the corresponding data direction and output latch registers are trisc and latc. only portc pins, rc2 through rc7, are digital only pins. portc is multiplexed with ccp, mssp and eusart peripheral functions ( table 11-5 ). the pins have schmitt trigger input buffers. the pins for ccp, spi and eusart are also configurable for open-drain out- put whenever these functions are active. open-drain configuration is selected by setting the sspod, ccpxod and u1od control bits in the odcon register. rc1 is configurable for open-drain output when ccp2 is active on this pin. open-drain configuration is selected by setting the ccp2od control bit (odcon<3>). when enabling peripheral functions, use care in defin- ing tris bits for each portc pin. some peripherals can override the tris bit to make a pin an output or input. consult the corresponding peripheral section for the correct tris bit settings. the contents of the trisc register are affected by peripheral overrides. reading trisc always returns the current contents, even though a peripheral device may be overriding one or more of the pins. example 11-3: initializing portc note: these pins are configured as digital inputs on any device reset. clrf portc ; initialize portc by ; clearing output ; data latches clrf latc ; alternate method ; to clear output ; data latches movlw 0cfh ; value used to ; initialize data ; direction movwf trisc ; set rc<3:0> as inputs ; rc<5:4> as outputs ; rc<7:6> as inputs
pic18f66k80 family ds39977d-page 186 ? 2011 microchip technology inc. table 11-5: portc functions pin name function tris setting i/o i/o type description rc0/sosco/ sclki rc0 0 o dig latc<0> data output. 1 i st portc<0> data input. sosco 1 i st sosc oscillator output. sclki 1 i st digital clock input; enabled when sosc oscillator is disabled. rc1/sosci rc1 0 o dig latc<1> data output. 1 i st portc<1> data input. sosci x i ana sosc oscillator input. rc2/t1g/ ccp2 rc2 0 o dig latc<2> data output. 1 i st portc<2> data input. t1g x i st timer1 external clock gate input. ccp2 0 o dig ccp2 compare/pwm output. takes priority over port data. 1 i st ccp2 capture input. rc3/refo/ scl/sck rc3 0 o dig latc<3> data output. 1 i st portc<3> data input. refo x o dig reference output clock. scl 0 odigi 2 c? clock output (mssp module); takes priority over port data. 1 ii 2 ci 2 c clock input (mssp module); input type depends on module setting. sck 0 o dig spi clock output (mssp module); takes priority over port data. 1 i st spi clock input (mssp module). rc4/sda/sdi rc4 0 o dig latc<4> data output. 1 i st portc<4> data input. sda 1 odigi 2 c data output (mssp module); takes priority over port data. 1 ii 2 ci 2 c data input (mssp module); input type depends on module setting. sdi 1 i st spi data input (mssp module). rc5/sdo rc5 0 o dig latc<5> data output. 1 i st portc<5> data input. sdo 0 o dig spi data output (mssp module). rc6/cantx/ tx1/ck1/ ccp3 rc6 0 o dig latc<6> data output. 1 i st portc<6> data input. cantx (1) 0 o dig can bus tx. tx1 (1) 0 o dig asynchronous serial data output (eusart module); takes priority over port data. ck1 (1) 0 o dig synchronous serial clock output (eusar t module); user must configure as an input. 1 i st synchronous serial clock input (eusar t module); user must configure as an input. ccp3 0 o dig ccp3 compare/pwm output. takes priority over port data. 1 i st ccp3 capture input. legend: o = output, i = input, i 2 c = i 2 c/smbus, ana = analog signal, dig = cmos output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option) note 1: pin assignment for 28, 40 and 44-pin devices (pic18f2xk80 and pic18f4xk80). 2: alternate pin assignment for canrx and cantx on 28, 40 and 44-pin devices (pic18f4xk80) when the canmx configuration bit is set.
? 2011 microchip technology inc. ds39977d-page 187 pic18f66k80 family table 11-6: summary of register s associated with portc rc7/canrx/ rx1/dt1/ ccp4 rc7 0 o dig latc<7> data output. 1 i st portc<7> data input. canrx (1) 1 i st can bus rx. rx1 (1) 1 i st asynchronous serial receive data input (eusart module). dt1 (1) 1 o dig synchronous serial data output (eusart module); takes priority over port data. 1 i st synchronous serial data input (eusart module); user must configure as an input. ccp4 0 o dig ccp4 compare/pwm output. takes priority over port data. 1 i st ccp4 capture input. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 portc rc7 rc6 rc5 rc4 rc3 rc2 rc1 rc0 latc latc7 latbc6 latc5 latcb4 latc3 latc2 latc1 latc0 trisc trisc7 trisc6 trisc5 trisc 4trisc3trisc2trisc1trisc0 odcon sspod ccp5od ccp4od ccp3od ccp2od ccp1od u2od u1od legend: shaded cells are not used by portc. table 11-5: portc functions (continued) pin name function tris setting i/o i/o type description legend: o = output, i = input, i 2 c = i 2 c/smbus, ana = analog signal, dig = cmos output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option) note 1: pin assignment for 28, 40 and 44-pin devices (pic18f2xk80 and pic18f4xk80). 2: alternate pin assignment for canrx and cantx on 28, 40 and 44-pin devices (pic18f4xk80) when the canmx configuration bit is set.
pic18f66k80 family ds39977d-page 188 ? 2011 microchip technology inc. 11.5 portd, trisd and latd registers portd is an 8-bit wide, bidirectional port. the corresponding data direction and output latch registers are trisd and latd. all pins on portd are implemented with schmitt trigger input buffers. each pin is individually configurable as an input or output. each of the portd pins has a weak internal pull-up. a single control bit can turn off all the pull-ups. this is performed by setting bit, rdpu (padcfg1<7>). the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on all device resets. portd can also be configured as an 8-bit wide micro- processor port (parallel slave port) by setting control bit, pspmode (pspcon<4>). in this mode, the input buffers are st. for additional information, see section 11.9 ?parallel slave port? . rd3 has a ctmu functionality. example 11-4: initializing portd note: portd is unavailable on 28-pin devices. note: these pins are configured as digital inputs on any device reset. clrf portd ; initialize portd by ; clearing output ; data latches clrf latd ; alternate method ; to clear output ; data latches movlw 0cfh ; value used to ; initialize data ; direction movwf trisd ; set rd<3:0> as inputs ; rd<5:4> as outputs ; rd<7:6> as inputs
? 2011 microchip technology inc. ds39977d-page 189 pic18f66k80 family table 11-7: portd functions pin name function tris setting i/o i/o type description rd0/c1ina/ psp0 rd0 0 o dig latd<0> data output. 1 i st portd<0> data input. c1ina 1 i ana comparator 1 input a. psp0 x i/o st parallel slave port data. rd1/c1inb/ psp1 rd1 (1) 0 o dig latd<1> data output. 1 i st portd<1> data input. c1inb (1) 1 i ana comparator 1 input b. psp1 (1) x i/o st parallel slave port data. rd2/c2ina/ psp2 rd2 0 o dig latd<2> data output. 1 i st portd<2> data input. c2ina 1 i ana comparator 2 input a. psp2 x i/o st parallel slave port data. rd3/c2inb/ ctmui/psp3 rd3 0 o dig latd<3> data output. 1 i st portd<3> data input. c2inb 1 i ana comparator 2 input b. ctmui x i ? ctmu pulse generator charger for the c2inb comparator input. psp3 x i/o st parallel slave port data. rd4/eccp1/ p1a/psp4 rd4 0 o dig latd<4> data output. 1 i st portd<4> data input. eccp1 0 o dig eccp1 compare output and eccp1 pwm output. takes priority over port data. 1 i st eccp1 capture input. p1a 0 o dig eccp1 enhanced pwm output, channel a. may be configured for tri-state during enhanced pwm shutdown events. takes priority over port data. psp4 x i/o st parallel slave port data. rd5/p1b/psp5 rd5 0 o dig latd<5> data output. 1 i st portd<5> data input. p1b 0 o dig eccp1 enhanced pwm output, channel b. may be configured for tri-state during enhanced pwm shutdown events. takes priority over port data. psp5 x i/o st parallel slave port data. rd6/tx2/ck2 p1c/psp6 rd6 0 o dig latd<6> data output. 1 i st portd<6> data input. tx2 (1) 0 o dig asynchronous serial data output (eusart module); takes priority over port data. ck2 (1) 0 o dig synchronous serial clock output (eusart module); user must configure as an input. 1 i st synchronous serial clock input (eusart module); user must configure as an input. p1c 0 o dig eccp1 enhanced pwm output, channel c. may be configured for tri-state during enhanced pwm. psp6 x i/o st parallel slave port data. legend: o = output, i = input, ana = analog signal, dig = cmos output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option) note 1: pin assignment for 40 and 44-pin devices (pic18f4xk80).
pic18f66k80 family ds39977d-page 190 ? 2011 microchip technology inc. table 11-8: summary of register s associated with portd rd7/rx2/dt2/ p1d/psp7 rd7 0 o dig latd<7> data output. 1 i st portd<7> data input. rx2 (1) 1 i st asynchronous serial receiv e data input (eusart module). dt2 (1) 1 o dig synchronous serial data output (eusart module); takes priority over port data. 1 i st synchronous serial data input (e usart module); user must configure as an input. p1d 0 o dig eccp1 enhanced pwm output, channel d. may be configured for tri-state during enhanced pwm. psp7 x i/o st parallel slave port data. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 portd rd7 rd6 rd5 rd4 rd3 rd2 rd1 rd0 latd latd7 latd6 latd5 latd4 latd3 latd2 latd1 latd0 trisd trisd7 trisd6 trisd5 trisd4 trisd3 trisd2 trisd1 trisd0 padcfg1 rdpu (1) repu (1) rfpu (2) rgpu (2) ? ? ? ctmuds odcon sspod ccp5od ccp4od ccp3od ccp2od ccp1od u2od u1od ancon1 ? ansel14 ansel13 ansel12 ansel11 ansel10 ansel9 ansel8 legend: shaded cells are not used by portd. note 1: unimplemented on 28-pin devices, read as ? 0 ?. 2: unimplemented on 28/40/44-pin devices, read as ? 0 ?. table 11-7: portd functions (continued) pin name function tris setting i/o i/o type description legend: o = output, i = input, ana = analog signal, dig = cmos output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option) note 1: pin assignment for 40 and 44-pin devices (pic18f4xk80).
? 2011 microchip technology inc. ds39977d-page 191 pic18f66k80 family 11.6 porte, trise and late registers porte is a seven-bit-wide, bidirectional port. the corresponding data direction and output latch registers are trise and late. all pins on porte are implemented with schmitt trigger input buffers. each pin is individually configurable as an input or output. each of the porte pins has a weak internal pull-up. a single control bit can turn off all the pull-ups. this is performed by clearing bit, repu (padcfg1<6>). the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on any device reset. porte is also multiplexed with the parallel slave port address lines. re1 and re0 are multiplexed with the parallel slave port (psp) control signals, wr and rd . example 11-5: initializing porte note: porte is unavailable on 28-pin devices. note: these pins are configured as digital inputs on any device reset. clrf porte ; initialize porte by ; clearing output ; data latches clrf late ; alternate method ; to clear output ; data latches movlw 03h ; value used to ; initialize data ; direction movwf trise ; set re<1:0> as inputs ; re<7:2> as outputs table 11-9: porte functions pin name function tris setting i/o i/o type description re0/an5/rd re0 0 o dig late<0> data output. 1 i st porte<0> data input. an5 1 i ana a/d input channel 5. default input configuration on por; does not affect digital output. rd x o dig parallel slave port read strobe pin. x i st parallel slave port read pin. re1/an6/ c1out/wr re1 0 o dig late<1> data output. 1 i st porte<1> data input. an6 1 i ana a/d input channel 5. default input configuration on por; does not affect digital output. c1out 0 o dig comparator 1 output; takes priority over port data. wr x o dig parallel slave port write strobe pin. x i st parallel slave port write pin. re2/an7/ c2out/cs re2 0 o dig late<2> data output. 1 i st porte<2> data input. an7 1 i ana a/d input channel 7. default input configuration on por; does not affect digital output. c2out 0 o dig comparator 2 output; takes priority over port data. cs x i st parallel slave port chip select. re3 re3 1 i st port<3> data input. re4/canrx re4 (1) 0 o dig late<4> data output. 1 i st porte<4> data input. canrx (1,2) 1 i st can bus rx. legend: o = output, i = input, ana = analog signal, dig = cmos output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option) note 1: unavailable for 40 and 44-pi n devices (pic18f4xk0). 2: alternate pin assignment for canrx and cantx on 64-pin devices (pic18f6xk80) when the canmx configuration bit is cleared.
pic18f66k80 family ds39977d-page 192 ? 2011 microchip technology inc. table 11-10: summary of registers associated with porte re5/cantx re5 (1) 0 o dig late<5> data output. 1 i st porte<5> data input. cantx (1,2) 0 o dig can bus tx. re6/rx2/dt2 re6 (1) 0 o dig late<6> data output. 1 i st porte<6> data input. rx2 (1) 1 i st asynchronous serial receiv e data input (eusart module). dt2 (1) 1 o dig synchronous serial data output (eusart module); takes priority over port data. 1 i st synchronous serial data input (e usart module); user must configure as an input. re7/tx2/ck2 re7 (1) 0 o dig late<7> data output. 1 i st porte<7> data input. tx2 (1) 0 o dig asynchronous serial data output (eusart module); takes priority over port data. ck2 (1) 0 o dig synchronous serial clock output (eusart module); user must configure as an input. 1 i st synchronous serial clock input (eusart module); user must configure as an input. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 porte re7 (1) re6 (1) re5 (1) re4 (1) re3 re2 re1 re0 late late7 late6 late5 late4 ? late2 late1 late0 trise trise7 trise6 trise5 trise4 ? trise2 trise1 trise0 padcfg1 rdpu repu rfpu (1) rgpu (1) ? ? ? ctmuds ancon0 ansel7 ansel6 ansel5 ansel4 ansel3 ansel2 ansel1 ansel0 legend: shaded cells are not used by porte. note 1: unimplemented on 44-pin devices, read as ? 0 ?. table 11-9: porte functions (continued) pin name function tris setting i/o i/o type description legend: o = output, i = input, ana = analog signal, dig = cmos output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option) note 1: unavailable for 40 and 44-pi n devices (pic18f4xk0). 2: alternate pin assignment for canrx and cantx on 64-pin devices (pic18f6xk80) when the canmx configuration bit is cleared.
? 2011 microchip technology inc. ds39977d-page 193 pic18f66k80 family 11.7 portf, latf and trisf registers portf is an 8-bit wide, bidirectional port. the corresponding data direction and output latch registers are trisf and latf. all pins on portf are implemented with schmitt trigger input buffers. each pin is individually configurable as an input or output. each of the portf pins has a weak internal pull-up. a single control bit can turn off all the pull-ups. this is done by clearing bit, rfpu (padcfg1<5>). the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on any device reset. example 11-6: initializing portf table 11-12: summary of registers associated with portf note: portf is only available on 64-pin devices. note: on device resets, pins, rf<7:1>, are configured as analog inputs and are read as ? 0 ?. clrf portf ; initialize portf by ; clearing output ; data latches clrf latf ; alternate method ; to clear output ; data latches movlw 0ceh ; value used to ; initialize data ; direction movwf trisf ; set rf3:rf1 as inputs ; rf5:rf4 as outputs ; rf7:rf6 as inputs table 11-11: portf functions (legend:) pin name function tris setting i/o i/o type description rf0/mdmin rf0 0 o dig latf<0> data output. 1 i st portf<0> data input. mdmin 1 i st modulator source input. rf1 rf1 0 o dig latf<1> data output. 1 i st portf<1> data input. rf2/mdcin1 rf2 0 o dig latf<2> data output. 1 i st portf<2> data input. mdcin1 1 i st modulator carrier input 1. rf3 rf3 0 o dig latf<3> data output. 1 i st portf<3> data input. rf4/mdcin2 rf4 0 o dig latf<4> data output. 1 i st portf<4> data input. mdcin2 1 i st modulator carrier input 2. rf5 rf5 0 o dig latf<5> data output. 1 i st portf<5> data input. rf6/mdout rf6 0 o dig latf<6> data output. 1 i st portf<6> data input. mdout 0 o dig modulator output. rf7 rf7 0 o dig latf<7> data output. 1 i st portf<7> data input. legend: o = output, i = input, ana = analog signal, dig = cmos output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option) name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 portf rf7 rf6 rf5 rf4 rf3 rf2 rf1 rf0 latf latf7 latf6 latf5 latf4 ? latf2 latf1 latf0 trisf trisf7 trisf6 trisf5 trisf 4 trisf3 trisf2 trisf1 trisf0 padcfg1 rdpu repu rfpu (1) rgpu (1) ? ? ? ctmuds legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by portf. note 1: unimplemented on 28-pin devices; read as ? 0 ?.
pic18f66k80 family ds39977d-page 194 ? 2011 microchip technology inc. 11.8 portg, trisg and latg registers portg is a 5-bit wide, bidirectional port. the corresponding data direction and output latch registers are trisg and latg. portg is multiplexed with eusart and ccp, eccp, analog, comparator and timer input functions ( table 11-13 ). when operating as i/o, all portg pins have schmitt trigger input buffers. the open-drain functionality for the uart can be configured using odcon. each of the portg pins has a weak internal pull-up. a single control bit can turn off all the pull-ups. this is per- formed by clearing bit, rgpu (padcfg1<4>). the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on any device reset. when enabling peripheral functions, care should be taken in defining tris bits for each portg pin. some peripherals override the tris bit to make a pin an out- put, while other peripherals override the tris bit to make a pin an input. the user should refer to the corresponding peripheral section for the correct tris bit settings. the pin override value is not loaded into the tris register. this allows read-modify-write of the tris register without concern due to peripheral overrides. example 11-7: initializing portg note: portg is only available on 64-pin devices. clrf portg ; initialize portg by ; clearing output ; data latches clrf latg ; alternate method ; to clear output ; data latches movlw 04h ; value used to ; initialize data ; direction movwf trisg ; set rg1:rg0 as ; outputs ; rg2 as input ; rg4:rg3 as inputs table 11-13: portg functions pin name function tris setting i/o i/o type description rg0/rx1/dt1 rg0 0 o dig latg<0> data output. 1 i st portg<0> data input. rx1 1 i st asynchronous serial receiv e data input (eusart module). dt1 0 o dig synchronous serial data output (eusart module); takes priority over port data. 1 i st synchronous serial data input (e usart module); user must configure as an input. rg1/cantx rg1 0 o dig latg<1> data output. 1 i st portg<1> data input. cantx 0 o dig can bus tx. rg2/t3cki rg2 0 o dig latg<2> data output. 1 i st portg<2> data input. t3cki (2) x i st timer3 clock input. rg3/tx1/ck1 rg3 0 o dig latg<3> data output. 1 i st portg<3> data input. tx1 0 o dig asynchronous serial data output (eusart module); takes priority over port data. ck1 0 o dig synchronous serial clock output (eusart module); user must configure as an input. 1 i st synchronous serial clock input (eusart module); user must configure as an input. legend: o = output, i = input, ana = analog signal, dig = cmos output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option) note 1: alternate pin assignment for t0cki on 64-pin devices when the t0ckmx configuration bit is cleared. 2: default pin assignment for t3cki on 64-pin devices when the t3ckmx configuration bit is set.
? 2011 microchip technology inc. ds39977d-page 195 pic18f66k80 family table 11-14: summary of register s associated with portg rg4/t0cki rg4 0 o dig latg<4> data output. 1 i st portg<4> data input. t0cki (1) x i st timer0 clock input. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 portg ? ? ? rg4 rg3 rg2 rg1 rg0 trisg ? ? ? trisg4 trisg3 trisg2 trisg1 trisg0 padcfg1 rdpu repu rfpu (1) rgpu (1) ? ? ? ctmuds legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by portg. note 1: unimplemented on 28-pin devices. read as ? 0 ?. table 11-13: portg functions (continued) pin name function tris setting i/o i/o type description legend: o = output, i = input, ana = analog signal, dig = cmos output, st = schmitt trigger buffer input, x = don?t care (tris bit does not affect port direction or is overridden for this option) note 1: alternate pin assignment for t0cki on 64-pin devices when the t0ckmx configuration bit is cleared. 2: default pin assignment for t3cki on 64-pin devices when the t3ckmx configuration bit is set.
pic18f66k80 family ds39977d-page 196 ? 2011 microchip technology inc. 11.9 parallel slave port portd can function as an 8-bit-wide parallel slave port (psp), or microprocessor port, when control bit, pspmode (pspcon<4>), is set. the port is asyn- chronously readable and writable by the external world through the rd control input pin (re0/an5/rd ) and wr control input pin (re1/an6/c1out/wr ). the psp can directly interface to an 8-bit micro- processor data bus. the external microprocessor can read or write the portd latch as an eight-bit latch. setting bit, pspmode, enables port pin, re0/an5/r d , to be the rd input, re1/an6/c1out/wr to be the wr input and re2/an7/c2out/cs to be the cs (chip select) input. for this functionality, the corresponding data direction bits of the trise register (trise<2:0>) must be configured as inputs (= 111 ). a write to the psp occurs when both the cs and wr lines are first detected low and ends when either are detected high. the pspif and ibf flag bits (pir1<7> and pspcon<7>, respectively) are set when the write ends. a read from the psp occurs when both the cs and rd lines are first detected low. the data in portd is read out and the obf bit (pspcon<6>) is set. if the user writes new data to portd to set obf, the data is immediately read out, but the obf bit is not set. when either the cs or rd line is detected high, the portd pins return to the input state and the pspif bit is set. user applications should wait for pspif to be set before servicing the psp. when this happens, the ibf and obf bits can be polled and the appropriate action taken. the timing for the control signals in write and read modes is shown in figure 11-4 and figure 11-5 , respectively. figure 11-3: portd and porte block diagram (parallel slave port) note: the parallel slave port is available only on 40/44-pin and 64-pin devices. data bus wr latd rdx q d ck en qd en rd portd pin one bit of portd set interrupt flag pspif (pir1<7>) read chip select write rd cs wr note: the i/o pin has protection diodes to v dd and v ss . st st st st or portd rd latd data latch tris latch
? 2011 microchip technology inc. ds39977d-page 197 pic18f66k80 family figure 11-4: parallel slave port write waveforms register 11-5: pspcon: paralle l slave port co ntrol register r-0 r-0 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ibf obf ibov pspmode ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ibf: input buffer full status bit 1 = a word has been received and is waiting to be read by the cpu 0 = no word has been received bit 6 obf: output buffer full status bit 1 = the output buffer still holds a previously written word 0 = the output buffer has been read bit 5 ibov: input buffer overflow detect bit 1 = a write occurred when a previously input word had not been read (must be cleared in software) 0 = no overflow occurred bit 4 pspmode: parallel slave port mode select bit 1 = parallel slave port mode 0 = general purpose i/o mode bit 3-0 unimplemented: read as ? 0 ? q1 q2 q3 q4 cs q1 q2 q3 q4 q1 q2 q3 q4 wr rd ibf obf pspif portd<7:0>
pic18f66k80 family ds39977d-page 198 ? 2011 microchip technology inc. figure 11-5: parallel slave port read waveforms table 11-15: registers associated with parallel slave port name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 portd rd7 rd6 rd5 rd4 rd3 rd2 rd1 rd0 latd latd7 latd6 latd5 latd4 latd3 latd2 latd1 latd0 trisd trisd7 trisd6 trisd5 trisd4 trisd3 trisd2 trisd1 trisd0 porte re7 re6 re5 re4 re3 re2 re1 re0 late late7 late6 late5 late4 ? late2 late1 late0 trise trise7 trise6 trise5 trise4 ? trise2 trise1 trise0 pspcon ibf obf ibov pspmode ? ? ? ? intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif pir1 pspif adif rc1if tx1if sspif tmr1gif tmr2if tmr1if pie1 pspie adie rc1ie tx1ie sspie tmr1gie tmr2ie tmr1ie ipr1 pspip adip rc1ip tx1ip sspip tmr1gip tmr2ip tmr1ip pmd1 pspmd ctmumd adcmd tmr4md tmr3md tmr2md tmr1md tmr0md legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the parallel slave port. q1 q2 q3 q4 cs q1 q2 q3 q4 q1 q2 q3 q4 wr ibf pspif rd obf portd<7:0>
? 2011 microchip technology inc. ds39977d-page 199 pic18f66k80 family 12.0 data signal modulator the data signal modulator (dsm) is a peripheral which allows the user to mix a data stream, also known as a modulator signal, with a carrier signal to produce a modulated output. both the carrier and the modulator signals are supplied to the dsm module, either internally from the output of a peripheral, or externally through an input pin. the modulated output signal is generated by perform- ing a logical ?and? operation of both the carrier and modulator signals and then it is provided to the mdout pin. the carrier signal is comprised of two distinct and sepa- rate signals: a carrier high (carh) signal and a carrier low (carl) signal. during the time in which the modula- tor (mod) signal is in a logic high state, the dsm mixes the carrier high signal with the modulator signal. when the modulator signal is in a logic low state, the dsm mixes the carrier low signal with the modulator signal. using this method, the dsm can generate the following types of key modulation schemes: ? frequency-shift keying (fsk) ? phase-shift keying (psk) ? on-off keying (ook) additionally, the following features are provided within the dsm module: ? carrier synchronization ? carrier source polarity select ? carrier source pin disable ? programmable modulator data ? modulator source pin disable ? modulated output polarity select ? slew rate control figure 12-1 shows a simplified block diagram of the data signal modulator peripheral. note: the data signal modulator is only avail- able on 64-pin devices (pic18f6xk80).
pic18f66k80 family ds39977d-page 200 ? 2011 microchip technology inc. figure 12-1: simplified block diagram of the data signal modulator d q mdbit mdmin ssp (sdo) eusart1 (tx) eusart2 (tx) eccp1 ccp2 ccp3 reserved 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 no channel selected v ss mdcin1 mdcin2 refo clock eccp1 ccp2 ccp3 ccp4 0000 0001 0010 0011 0100 0101 0110 0111 1000 1111 1001 * * reserved no channel selected v ss mdcin1 mdcin2 refo clock eccp1 ccp2 ccp3 ccp4 0000 0001 0010 0011 0100 0101 0110 0111 1000 1111 mdch<3:0> mdms<3:0> mdcl<3:0> 1111 * * ccp4 ccp5 sync mdchpol mdclpol d q 1 0 sync 1 0 mdchsync mdclsync mdout mdopol mdoe carh carl en mden data signal modulator mod ccp5 1001 ccp5 * * reserved no channel selected
? 2011 microchip technology inc. ds39977d-page 201 pic18f66k80 family 12.1 dsm operation the dsm module can be enabled by setting the mden bit in the mdcon register. clearing the mden bit in the mdcon register, disables the dsm module by auto- matically switching the carrier high and carrier low signals to the v ss signal source. the modulator signal source is also switched to the mdbit in the mdcon register. this not only assures that the dsm module is inactive, but that it is also consuming the least amount of current. the values used to select the carrier high, carrier low and modulator sources held by the modulation source, modulation high carrier and modulation low carrier control registers are not affected when the mden bit is cleared, and the dsm module is disabled. the values inside these registers remain unchanged while the dsm is inactive. the sources for the carrier high, carrier low and modulator signals will once again be selected when the mden bit is set and the dsm module is again enabled and active. the modulated output signal can be disabled without shutting down the dsm module. the dsm module will remain active and continue to mix signals, but the out- put value will not be sent to the mdout pin. during the time that the output is disabled, the mdout pin will remain low. the modulated output can be disabled by clearing the mdoe bit in the mdcon register. 12.2 modulator signal sources the modulator signal can be supplied from the following sources: ? eccp1 signal ? ccp2 signal ? ccp3 signal ? ccp4 signal ? ccp5 signal ? mssp sdo signal (spi mode only) ? eusart1 tx1 signal ? eusart2 tx2 signal ? external signal on mdmin pin (rf0/mdmin) ? mdbit bit in the mdcon register the modulator signal is selected by configuring the mdsrc<3:0> bits in the mdsrc register. 12.3 carrier signal sources the carrier high signal and carrier low signal can be supplied from the following sources: ? ccp1 signal ? ccp2 signal ? ccp3 signal ? ccp4 signal ? reference clock module signal ? external signal on mdcin1 pin (rf2/mdcin1) ? external signal on mdcin2 pin (rf4/mdcin2) ?v ss the carrier high signal is selected by configuring the mdch<3:0> bits in the mdcarh register. the carrier low signal is selected by configuring the mdcl<3:0> bits in the mdcarl register. 12.4 carrier synchronization during the time when the dsm switches between car- rier high and carrier low signal sources, the carrier data in the modulated output signal can become truncated. to prevent this, the carrier signal can be synchronized to the modulator signal. when synchronization is enabled, the carrier pulse that is being mixed at the time of the transition is allowed to transition low before the dsm switches over to the next carrier source. synchronization is enabled separately for the carrier high and carrier low signal sources. synchronization for the carrier high signal can be enabled by setting the mdchsync bit in the mdcarh register. synchroniza- tion for the carrier low signal can be enabled by setting the mdclsync bit in the mdcarl register. figure 12-1 through figure 12-5 show timing diagrams of using various synchronization methods.
pic18f66k80 family ds39977d-page 202 ? 2011 microchip technology inc. figure 12-2: on-off keying (ook) synchronization example 12-1: no synchronization (mdchsync = 0 , mdclsync = 0 ) figure 12-3: carrier high synchronization (mdchsync = 1 , mdclsync = 0 ) carrier low (carl) mdchsync = 1 mdclsync = 0 mdchsync = 1 mdclsync = 1 mdchsync = 0 mdclsync = 0 mdchsync = 0 mdclsync = 1 carrier high (carh) modulator (mod) mdchsync = 0 mdclsync = 0 modulator (mod) carrier high (carh) carrier low (carl) active carrier carh carl carl carh state mdchsync = 1 mdclsync = 0 modulator (mod) carrier high (carh) carrier low (carl) active carrier carh carl carl carh state both both
? 2011 microchip technology inc. ds39977d-page 203 pic18f66k80 family figure 12-4: carrier low synchronization (mdchsync = 0 , mdclsync = 1 ) figure 12-5: full synchronization (mdchsync = 1 , mdclsync = 1 ) mdchsync = 0 mdclsync = 1 modulator (mod) carrier high (carh) carrier low (carl) active carrier carh carl carl carh state mdchsync = 1 mdclsync = 1 modulator (mod) carrier high (carh) carrier low (carl) active carrier carh carl carl carh state falling edges used to sync
pic18f66k80 family ds39977d-page 204 ? 2011 microchip technology inc. 12.5 carrier source polarity select the signal provided from any selected input source for the carrier high and carrier low signals can be inverted. inverting the signal for the carrier high source is enabled by setting the mdchpol bit of the mdcarh register. inverting the signal for the carrier low source is enabled by setting the mdclpol bit of the mdcarl register. 12.6 carrier source pin disable some peripherals assert control over their correspond- ing output pin when they are enabled. for example, when the ccp1 module is enabled, the output of ccp1 is connected to the ccp1 pin. this default connection to a pin can be disabled by setting the mdchodis bit in the mdcarh register for the carrier high source and the mdclodis bit in the mdcarl register for the carrier low source. 12.7 programmable modulator data the mdbit of the mdcon register can be selected as the source for the modulator signal. this gives the user the ability to program the value used for modulation. 12.8 modulator source pin disable the modulator source default connection to a pin can be disabled by setting the mdsodis bit in the mdsrc register. 12.9 modulated output polarity the modulated output signal provided on the mdout pin can also be inverted. inverting the modulated out- put signal is enabled by setting the mdopol bit of the mdcon register. 12.10 slew rate control when modulated data streams of 20 mhz or greater are required, the slew rate limitation on the output port pin can be disabled. the slew rate limitation can be removed by clearing the mdslr bit in the mdcon register. 12.11 operation in sleep mode the dsm module is not affected by sleep mode. the dsm can still operate during sleep if the carrier and modulator input sources are also still operable during sleep. 12.12 effects of a reset upon any device reset, the data signal modulator module is disabled. the user?s firmware is responsible for initializing the module before enabling the output. the registers are reset to their default values.
? 2011 microchip technology inc. ds39977d-page 205 pic18f66k80 family register 12-1: mdcon: modu lation control register r/w-0 r/w-0 r/w-1 r/w-0 r/w-0 u-0 u-0 r/w-0 mden mdoe mdslr mdopol mdo ? ?mdbit bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 mden: modulator module enable bit 1 = modulator module is enabled and mixing input signals 0 = modulator module is disabled and has no output bit 6 mdoe: modulator module pin output enable bit 1 = modulator pin output enabled 0 = modulator pin output disabled bit 5 mdslr: mdout pin slew rate limiting bit 1 = mdout pin slew rate limiting enabled 0 = mdout pin slew rate limiting disabled bit 4 mdopol: modulator output polarity select bit 1 = modulator output signal is inverted 0 = modulator output signal is not inverted bit 3 mdo: modulator output bit displays the current output value of the modulator module. (2) bit 2-1 unimplemented: read as ? 0 ? bit 0 mdbit: modulator source input bit allows software to manually set modulation source input to module. (1) note 1: the mdbit must be selected as the modulation source in the mdsrc register for this operation. 2: the modulated output frequency can be greater and asynchronous from the clock that updates this register bit. the bit value may not be valid for higher speed modulator or carrier signals.
pic18f66k80 family ds39977d-page 206 ? 2011 microchip technology inc. register 12-2: mdsrc: modulat ion source control register r/w-x u-0 u-0 u-0 r/w-x r/w-x r/w-x r/w-x mdsodis ? ? ? mdsrc3 mdsrc2 mdsrc1 mdsrc0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 mdsodis: modulation source output disable bit 1 = output signal driving the peripheral output pin (selected by mdms<3:0>) is disabled 0 = output signal driving the peripheral output pin (selected by mdms<3:0>) is enabled bit 6-4 unimplemented: read as ? 0 ? bit 3-0 mdsrc<3:0> modulation source selection bits 1111 - 1010 = reserved; no channel connected 1001 = ccp5 output (pwm output mode only) 1000 = ccp4 output (pwm output mode only) 0111 = ccp3 output (pwm output mode only) 0110 = ccp2 output (pwm output mode only) 0101 = eccp1 output (pwm output mode only) 0100 = eusart2 tx output 0011 = eusart1 tx output 0010 = mssp sdo output 0001 = mdmin port pin 0000 = mdbit bit of the mdcon register is the modulation source
? 2011 microchip technology inc. ds39977d-page 207 pic18f66k80 family register 12-3: mdcarh: modulation high carri er control register r/w-x r/w-x r/w-x u-0 r/w-x r/w-x r/w-x r/w-x mdchodis mdchpol mdchsync ? mdch3 (1) mdch2 (1) mdch1 (1) mdch0 (1) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 mdchodis: modulator high carrier output disable bit 1 = output signal driving the peripheral output pin (selected by mdch<3:0>) is disabled 0 = output signal driving the peripheral output pin (selected by mdch<3:0>) is enabled bit 6 mdchpol: modulator high carrier polarity select bit 1 = selected high carrier signal is inverted 0 = selected high carrier signal is not inverted bit 5 mdchsync: modulator high carrier synchronization enable bit 1 = modulator waits for a falling edge on the high time carrier signal before allowing a switch to the low time carrier 0 = modulator output is not synchronized to the high time carrier signal (1) bit 4 unimplemented: read as ? 0 ? bit 3-0 mdch<3:0> modulator data high carrier selection bits (1) 1111 - 1001 = reserved 1000 = ccp5 output (pwm output mode only) 0111 = ccp4 output (pwm output mode only) 0110 = ccp3 output (pwm output mode only) 0101 = ccp2 output (pwm output mode only) 0100 = eccp1 output (pwm output mode only) 0011 = reference clock module signal 0010 = mdcin2 port pin 0001 = mdcin1 port pin 0000 = v ss note 1: narrowed carrier pulse widths or spurs may occur in the signal stream if the carrier is not synchronized.
pic18f66k80 family ds39977d-page 208 ? 2011 microchip technology inc. table 12-1: summary of registers associ ated with data signal modulator mod e register 12-4: mdcarl: modulatio n low carrier control register r/w-0 r/w-x r/w-x u-0 r/w-x r/w-x r/w-x r/w-x mdclodis mdclpol mdclsync ? mdcl3 (1) mdcl2 (1) mdcl1 (1) mdcl0 (1) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 mdclodis: modulator low carrier output disable bit 1 = output signal driving the peripheral output pin (selected by mdcl<3:0> of the mdcarl register) is disabled 0 = output signal driving the peripheral output pin (selected by mdcl<3:0> of the mdcarl register) is enabled bit 6 mdclpol: modulator low carrier polarity select bit 1 = selected low carrier signal is inverted 0 = selected low carrier signal is not inverted bit 5 mdclsync: modulator low carrier synchronization enable bit 1 = modulator waits for a falling edge on the low time carrier signal before allowing a switch to the high time carrier 0 = modulator output is not synchronized to the low time carrier signal (1) bit 4 unimplemented: read as ? 0 ? bit 3-0 mdcl<3:0> modulator data high carrier selection bits (1) 1111 - 1001 = reserved 1000 = ccp5 output (pwm output mode only) 0111 = ccp4 output (pwm output mode only) 0110 = ccp3 output (pwm output mode only) 0101 = ccp2 output (pwm output mode only) 0100 = eccp1 output (pwm output mode only) 0011 = reference clock module signal 0010 = mdcin2 port pin 0001 = mdcin1 port pin 0000 = v ss note 1: narrowed carrier pulse widths or spurs may occur in the signal stream if the carrier is not synchronized. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 mdcarh mdchodis mdchpol mdchsync ? mdch3 mdch2 mdch1 mdch0 mdcarl mdclodis mdclpol mdclsync ? mdcl3 mdcl2 mdcl1 mdcl0 mdcon mden mdoe mdslr mdopol mdo ? ?mdbit mdsrc mdsodis ? ? ? mdsrc3 mdsrc2 mdsrc1 mdsrc0 pmd2 ? ? ? ?modmd ecanmd cmp2md cmp1md legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used in the data signal modulator mode.
? 2011 microchip technology inc. ds39977d-page 209 pic18f66k80 family 13.0 timer0 module the timer0 module incorporates the following features: ? software selectable operation as a timer or counter in both 8-bit or 16-bit modes ? readable and writable registers ? dedicated 8-bit, software programmable prescaler ? selectable clock source (internal or external) ? edge select for external clock ? interrupt-on-overflow the t0con register ( register 13-1 ) controls all aspects of the module?s operation, including the prescale selection. it is both readable and writable. figure 13-1 provides a simplified block diagram of the timer0 module in 8-bit mode. figure 13-2 provides a simplified block diagram of the timer0 module in 16-bit mode. register 13-1: t0con: ti mer0 control register r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 tmr0on t08bit t0cs t0se psa t0ps2 t0ps1 t0ps0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 tmr0on: timer0 on/off control bit 1 = enables timer0 0 = stops timer0 bit 6 t08bit : timer0 8-bit/16-bit control bit 1 = timer0 is configured as an 8-bit timer/counter 0 = timer0 is configured as a 16-bit timer/counter bit 5 t0cs : timer0 clock source select bit 1 = transition on t0cki pin 0 = internal instruction cycle clock (clko) bit 4 t0se : timer0 source edge select bit 1 = increment on high-to-low transition on t0cki pin 0 = increment on low-to-high transition on t0cki pin bit 3 psa : timer0 prescaler assignment bit 1 = timer0 prescaler is not assigned. timer0 clock input bypasses prescaler 0 = timer0 prescaler is assigned. timer0 clock input comes from prescaler output bit 2-0 t0ps<2:0> : timer0 prescaler select bits 111 = 1:256 prescale value 110 = 1:128 prescale value 101 = 1:64 prescale value 100 = 1:32 prescale value 011 = 1:16 prescale value 010 = 1:8 prescale value 001 = 1:4 prescale value 000 = 1:2 prescale value
pic18f66k80 family ds39977d-page 210 ? 2011 microchip technology inc. 13.1 timer0 operation timer0 can operate as either a timer or a counter. the mode is selected with the t0cs bit (t0con<5>). in timer mode (t0cs = 0 ), the module increments on every clock by default unless a different prescaler value is selected (see section 13.3 ?prescaler? ). if the tmr0 register is written to, the increment is inhibited for the following two instruction cycles. the user can work around this by writing an adjusted value to the tmr0 register. the counter mode is selected by setting the t0cs bit (= 1 ). in this mode, timer0 increments either on every rising edge or falling edge of the t0cki pin. the incrementing edge is determined by the timer0 source edge select bit, t0se (t0con<4>); clearing this bit selects the rising edge. restrictions on the external clock input are discussed below. an external clock source can be used to drive timer0; however, it must meet certain requirements to ensure that the external clock can be synchronized with the internal phase clock (t osc ). there is a delay between synchronization and the onset of incrementing the timer/counter. 13.2 timer0 reads and writes in 16-bit mode tmr0h is not the actual high byte of timer0 in 16-bit mode. it is actually a buffered version of the real high byte of timer0, which is not directly readable nor writable. (see figure 13-2 .) tmr0h is updated with the contents of the high byte of timer0 during a read of tmr0l. this provides the ability to read all 16 bits of timer0 without having to verify that the read of the high and low byte were valid, due to a rollover between successive reads of the high and low byte. similarly, a write to the high byte of timer0 must also take place through the tmr0h buffer register. the high byte is updated with the contents of tmr0h when a write occurs to tmr0l. this allows all 16 bits of timer0 to be updated at once. figure 13-1: timer0 block diagram (8-bit mode) figure 13-2: timer0 block diagram (16-bit mode) note: upon reset, timer0 is enabled in 8-bit mode with clock input from t0cki max. prescale. t0cki pin t0se 0 1 1 0 t0cs f osc /4 programmable prescaler sync with internal clocks tmr0l (2 t cy delay) internal data bus psa t0ps<2:0> set tmr0if on overflow 3 8 8 note: upon reset, timer0 is enabled in 8-bit mode wit h clock input from t0cki max. prescale. t0cki pin t0se 0 1 1 0 t0cs f osc /4 sync with internal clocks tmr0l (2 t cy delay) internal data bus 8 psa t0ps<2:0> set tmr0if on overflow 3 tmr0 tmr0h high byte 8 8 8 read tmr0l write tmr0l 8 programmable prescaler
? 2011 microchip technology inc. ds39977d-page 211 pic18f66k80 family 13.3 prescaler an 8-bit counter is available as a prescaler for the timer0 module. the prescaler is not directly readable or writable. its value is set by the psa and t0ps<2:0> bits (t0con<3:0>), which determine the prescaler assignment and prescale ratio. clearing the psa bit assigns the prescaler to the timer0 module. when it is assigned, prescale values from 1:2 through 1:256, in power-of-two increments, are selectable. when assigned to the timer0 module, all instructions writing to the tmr0 register (for example, clrf tmr0 , movwf tmr0 , bsf tmr0 ) clear the prescaler count. 13.3.1 switching prescaler assignment the prescaler assignment is fully under software control and can be changed ?on-the-fly? during program execution. 13.4 timer0 interrupt the tmr0 interrupt is generated when the tmr0 register overflows from ffh to 00h in 8-bit mode, or from ffffh to 0000h in 16-bit mode. this overflow sets the tmr0if flag bit. the interrupt can be masked by clearing the tmr0ie bit (intcon<5>). before re- enabling the interrupt, the tmr0if bit must be cleared in software by the interrupt service routine (isr). since timer0 is shutdown in sleep mode, the tmr0 interrupt cannot awaken the processor from sleep. table 13-1: registers associated with timer0 note: writing to tmr0 when the prescaler is assigned to timer0 will clear the prescaler count but will not change the prescaler assignment. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 tmr0l timer0 register low byte tmr0h timer0 register high byte intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif t0con tmr0on t08bit t0cs t0se psa t0ps2 t0ps1 t0ps0 pmd1 pspmd ctmumd adcmd tmr4md tmr3md tmr2md tmr1md tmr0md legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by timer0.
pic18f66k80 family ds39977d-page 212 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds39977d-page 213 pic18f66k80 family 14.0 timer1 module the timer1 timer/counter module incorporates these features: ? software selectable operation as a 16-bit timer or counter ? readable and writable 8-bit registers (tmr1h and tmr1l) ? selectable clock source (internal or external) with device clock or sosc oscillator internal options ? interrupt-on-overflow ? reset on eccp special event trigger ? timer with gated control figure 14-1 displays a simplified block diagram of the timer1 module. the module derives its clocking source from either the secondary oscillator or from an external digital source. if using the secondary oscillator, there are the addi- tional options for low-power, high-power and external, digital clock source. timer1 is controlled through the t1con control register ( register 14-1 ). it also contains the timer1 oscillator enable bit (soscen). timer1 can be enabled or disabled by setting or clearing control bit, tmr1on (t1con<0>). the f osc clock source should not be used with the eccp capture/compare features. if the timer will be used with the capture or compare features, always select one of the other timer clocking options. register 14-1: t1con: ti mer1 control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 tmr1cs1 tmr1cs0 t1ckps1 t1ckps0 soscen t1sync rd16 tmr1on bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 tmr1cs<1:0>: timer1 clock source select bits 10 = timer1 clock source is either from pin or oscillator, depending on the soscen bit: soscen = 0 : external clock is from the t1cki pin (on the rising edge). soscen = 1 : depending on the soscsel configuration bit, the clock source is either a crystal oscillator on sosci/sosco or an internal digital clock from the sclki pin. 01 = timer1 clock source is system clock (f osc ) (1) 00 = timer1 clock source is instruction clock (f osc /4) bit 5-4 t1ckps<1:0>: timer1 input clock prescale select bits 11 = 1:8 prescale value 10 = 1:4 prescale value 01 = 1:2 prescale value 00 = 1:1 prescale value bit 3 soscen: sosc oscillator enable bit 1 = sosc enabled and available for timer1 0 = sosc disabled for timer1 the oscillator inverter and feedback resistor are turned off to eliminate power drain. bit 2 t1sync : timer1 external clock input synchronization select bit tmr1cs<1:0> = 10 : 1 = do not synchronize external clock input 0 = synchronize external clock input tmr1cs<1:0> = 0x : this bit is ignored. timer1 uses the internal clock when tmr1cs<1:0> = 1x . note 1: the f osc clock source should not be selected if the timer will be used with the eccp capture/compare features.
pic18f66k80 family ds39977d-page 214 ? 2011 microchip technology inc. bit 1 rd16: 16-bit read/write mode enable bit 1 = enables register read/write of timer1 in one 16-bit operation 0 = enables register read/write of timer1 in two 8-bit operations bit 0 tmr1on: timer1 on bit 1 = enables timer1 0 =stops timer1 register 14-1: t1con: timer1 control register (continued) note 1: the f osc clock source should not be selected if the timer will be used with the eccp capture/compare features.
? 2011 microchip technology inc. ds39977d-page 215 pic18f66k80 family 14.1 timer1 gate control register the timer1 gate control register (t1gcon), displayed in register 14-2 , is used to control the timer1 gate. register 14-2: t1gcon: timer1 gate control register (1) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-x r/w-0 r/w-0 tmr1ge t1gpol t1gtm t1gspm t1ggo/t1done t1gval t1gss1 t1gss0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 tmr1ge: timer1 gate enable bit if tmr1on = 0 : this bit is ignored. if tmr1on = 1 : 1 = timer1 counting is controlled by the timer1 gate function 0 = timer1 counts regardless of timer1 gate function bit 6 t1gpol: timer1 gate polarity bit 1 = timer1 gate is active-high (timer1 counts when gate is high) 0 = timer1 gate is active-low (timer1 counts when gate is low) bit 5 t1gtm: timer1 gate toggle mode bit 1 = timer1 gate toggle mode is enabled 0 = timer1 gate toggle mode is disabled and toggle flip-flop is cleared timer1 gate flip-flop toggles on every rising edge. bit 4 t1gspm: timer1 gate single pulse mode bit 1 = timer1 gate single pulse mode is enabled and is controlling timer1 gate 0 = timer1 gate single pulse mode is disabled bit 3 t1ggo/t1done : timer1 gate single pulse acquisition status bit 1 = timer1 gate single pulse acquisition is ready, waiting for an edge 0 = timer1 gate single pulse acquisition has completed or has not been started this bit is automatically cleared when t1gspm is cleared. bit 2 t1gval: timer1 gate current state bit indicates the current state of the timer1 gate that could be provided to tmr1h:tmr1l; unaffected by timer1 gate enable (tmr1ge) bit. bit 1-0 t1gss<1:0>: timer1 gate source select bits 11 = comparator 2 output 10 = comparator 1 output 01 = tmr2 to match pr2 output 00 = timer1 gate pin note 1: programming the t1gcon prior to t1con is recommended.
pic18f66k80 family ds39977d-page 216 ? 2011 microchip technology inc. 14.2 timer1 operation the timer1 module is an 8 or 16-bit incrementing counter that is accessed through the tmr1h:tmr1l register pair. when used with an internal clock source, the module is a timer and increments on every instruction cycle. when used with an external clock source, the module can be used as either a timer or counter. it increments on every selected edge of the external source. timer1 is enabled by configuring the tmr1on and tmr1ge bits in the t1con and t1gcon registers, respectively. when sosc is selected as crystal mode (by soscsel), the rc1/sosci and rc0/sosco/sclki pins become inputs. this means the values of trisc<1:0> are ignored and the pins are read as ? 0 ?. 14.3 clock source selection the tmr1cs<1:0> and soscen bits of the t1con register are used to select the clock source for timer1. table 14-1 displays the clock source selections. 14.3.1 internal clock source when the internal clock source is selected, the tmr1h:tmr1l register pair will increment on multiples of f osc as determined by the timer1 prescaler. 14.3.2 external clock source when the external clock source is selected, the timer1 module may work as a timer or a counter. when enabled to count, timer1 is incremented on the rising edge of the external clock input, t1cki. either of these external clock sources can be synchronized to the microcontroller system clock or they can run asynchronously. when used as a timer with a clock oscillator, an external, 32.768 khz crystal can be used in conjunction with the dedicated internal oscillator circuit. table 14-1: timer1 clo ck source selection note: in counter mode, a falling edge must be registered by the counter prior to the first incrementing rising edge after any one or more of the following conditions: ? timer1 is enabled after por reset ? write to tmr1h or tmr1l ? timer1 is disabled ? timer1 is disabled (tmr1on = 0 ) when t1cki is high, timer1 is enabled (tmr1on = 1 ) when t1cki is low. tmr1cs1 tmr1cs0 soscen clock source 01x clock source (f osc ) 00x instruction clock (f osc /4) 100 external clock on t1cki pin 101 oscillator circuit on sosci/sosco pins
? 2011 microchip technology inc. ds39977d-page 217 pic18f66k80 family figure 14-1: timer1 block diagram tmr1h tmr1l t1sync t1ckps<1:0> prescaler 1, 2, 4, 8 0 1 synchronized clock input 2 set flag bit, tmr1if, on overflow tmr1 (2) tmr1on note 1: st buffer is high-speed type when using t1cki. 2: timer1 register increments on rising edge. 3: synchronize does not operate while in sleep. 4: the output of sosc is determined by the soscsel<1:0> configuration bits. t1g sosc f osc /4 internal clock sosco/sclki sosci 1 0 t1cki tmr1cs<1:0> (1) synchronize (3) det sleep input tmr1ge 0 1 00 01 10 11 from tmr2 from comparator 1 t1gpol d q ck q 0 1 t1gval t1gtm single pulse acq. control t1gspm t1ggo/t1done t1gss<1:0> en out (4) 10 00 01 f osc internal clock from comparator 2 match pr2 r d en q q1 rd t1gcon data bus det interrupt tmr1gif set t1clk f osc /2 internal clock d en q t1g_in tmr1on output output t1con.soscen t3con.soscen soscgo scs<1:0> = 01
pic18f66k80 family ds39977d-page 218 ? 2011 microchip technology inc. 14.4 timer1 16-bit read/write mode timer1 can be configured for 16-bit reads and writes. when the rd16 control bit (t1con<1>) is set, the address for tmr1h is mapped to a buffer register for the high byte of timer1. a read from tmr1l loads the contents of the high byte of timer1 into the timer1 high byte buffer register. this provides the user with the ability to accurately read all 16 bits of timer1 without having to determine whether a read of the high byte, followed by a read of the low byte, has become invalid due to a rollover between reads. a write to the high byte of timer1 must also take place through the tmr1h buffer register. the timer1 high byte is updated with the contents of tmr1h when a write occurs to tmr1l. this allows a user to write all 16 bits at once to both the high and low bytes of timer1. the high byte of timer1 is not directly readable or writable in this mode. all reads and writes must take place through the timer1 high byte buffer register. writes to tmr1h do not clear the timer1 prescaler. the prescaler is only cleared on writes to tmr1l. 14.5 sosc oscillator an on-chip crystal oscillator circuit is incorporated between pins, sosci (input) and sosco (amplifier output). it can be enabled one of these ways: ? setting the soscen bit in either the t1con or t3con register (txcon<3>) ? setting the soscgo bit in the osccon2 register (osccon2<3>) ? setting the scs bits to secondary clock source in the osccon register (osccon<1:0> = 01 ) the soscgo bit is used to warm up the sosc so that it is ready before any peripheral requests it. the oscillator is a low-power circuit rated for 32 khz crystals. it will continue to run during all power- managed modes. the circuit for a typical low-power oscillator is depicted in figure 14-2 . tab l e 1 4- 2 provides the capacitor selection for the sosc oscillator. the user must provide a software time delay to ensure proper start-up of the sosc oscillator. figure 14-2: external components for the sosc oscillator table 14-2: capacitor selection for the timer oscillator (2,3,4,5) the sosc crystal oscillator drive level is determined based on the soscsel (config1l<4:3>) configura- tion bits. the higher drive level mode, soscsel<1:0> = 11 , is intended to drive a wide variety of 32.768 khz crystals with a variety of load capacitance (cl) ratings. the lower drive level mode is highly optimized for extremely low-power consumption. it is not intended to drive all types of 32.768 khz crystals. in the low drive level mode, the crystal oscillator circuit may not work correctly if excessively large discrete capacitors are placed on the sosco and sosci pins. this mode is designed to work only with discrete capacitances of approximately 3 pf-10 pf on each pin. crystal manufacturers usually specify a cl (load capacitance) rating for their crystals. this value is related to, but not necessarily the same as, the values that should be used for c1 and c2 in figure 14-2 . oscillator type freq. c1 c2 lp 32 khz 12 pf (1) 12 pf (1) note 1: microchip suggests these values as a starting point in validating the oscillator circuit. 2: higher capacitance increases the stability of the oscillator, but also increases the start-up time. 3: since each resonator/crystal has its own characteristics, the us er should consult the resonator/crystal manufacturer for appropriate values of external components. 4: capacitor values are for design guidance only. values listed would be typical of a cl = 10 pf rated crystal, when soscsel = 11. 5: incorrect capacitance value may result in a fre- quency not meeting the crystal manufacturer?s tolerance specification. note: see the notes with table 14-2 for additional information about capacitor selection. c1 c2 xtal sosci sosco 32.768 khz 12 pf 12 pf pic18f66k80
? 2011 microchip technology inc. ds39977d-page 219 pic18f66k80 family for more details on selecting the optimum c1 and c2 for a given crystal, see the crystal manufacture?s appli- cations information. the optimum value depends in part on the amount of parasitic capacitance in the circuit, which is often unknown. for that reason, it is highly recommended that thorough testing and valida- tion of the oscillator be performed after values have been selected. 14.5.1 using sosc as a clock source the sosc oscillator is also available as a clock source in power-managed modes. by setting the clock select bits, scs<1:0> (osccon<1:0>), to ? 01 ?, the device switches to sec_run mode and both the cpu and peripherals are clocked from the sosc oscillator. if the idlen bit (osccon<7>) is cleared and a sleep instruction is executed, the device enters sec_idle mode. additional details are available in section 4.0 ?power-managed modes? . whenever the sosc oscillator is providing the clock source, the sosc system clock status flag, sosc- run (osccon2<6>), is set. this can be used to determine the controller?s current clocking mode. it can also indicate the clock source currently being used by the fail-safe clock monitor. if the clock monitor is enabled and the sosc oscillator fails while providing the clock, polling the socsrun bit will indicate whether the clock is being provided by the sosc oscillator or another source. 14.5.2 sosc oscillator layout considerations the sosc oscillator circuit draws very little power during operation. due to the low-power nature of the oscillator, it may also be sensitive to rapidly changing signals in close proximity. this is especially true when the oscillator is configured for extremely low-power mode, soscsel<1:0> (config1l<4:3>) = 01 . the oscillator circuit, displayed in figure 14-2 , should be located as close as possible to the microcontroller. there should be no circuits passing within the oscillator circuit boundaries other than v ss or v dd . if a high-speed circuit must be located near the oscillator, it may help to have a grounded guard ring around the oscillator circuit. the guard, as displayed in figure 14-3 , could be used on a single-sided pcb or in addition to a ground plane. (examples of a high-speed circuit include the eccp1 pin, in output compare or pwm mode, or the primary oscillator, using the osc2 pin.) figure 14-3: oscillator circuit with grounded guard ring in the low drive level mode, soscsel<1:0> = 01 , it is critical that rc2 i/o pin signals be kept away from the oscillator circuit. configuring rc2 as a digital output, and toggling it, can potentially disturb the oscillator circuit, even with a relatively good pcb layout. if possible, either leave rc2 unused or use it as an input pin with a slew rate limited signal source. if rc2 must be used as a digital output, it may be necessary to use the higher drive level oscillator mode (soscsel<1:0> = 11 ) with many pcb layouts. even in the higher drive level mode, careful layout procedures should still be followed when designing the oscillator circuit. in addition to dv/dt induced noise considerations, it is important to ensure that the circuit board is clean. even a very small amount of conductive, soldering flux residue can cause pcb leakage currents that can overwhelm the oscillator circuit. 14.6 timer1 interrupt the tmr1 register pair (tmr1h:tmr1l) increments from 0000h to ffffh and rolls over to 0000h. the timer1 interrupt, if enabled, is generated on overflow which is latched in interrupt flag bit, tmr1if (pir1<0>). this interrupt can be enabled or disabled by setting or clearing the timer1 interrupt enable bit, tmr1ie (pie1<0>). v dd osc1 v ss osc2 rc0 rc1 rc2 note: not drawn to scale.
pic18f66k80 family ds39977d-page 220 ? 2011 microchip technology inc. 14.7 resetting timer1 using the eccp special event trigger if eccp modules are configured to use timer1 and to generate a special event trigger in compare mode (ccp1m<3:0> = 1011 ), this signal will reset timer1. the trigger from eccp will also start an a/d conversion if the a/d module is enabled. (for more information, see section 20.3.4 ?special event trigger? .) to take advantage of this feature, the module must be configured as either a timer or a synchronous counter. when used this way, the ccpr1h:ccpr1l register pair effectively becomes a period register for timer1. if timer1 is running in asynchronous counter mode, this reset operation may not work. in the event that a write to timer1 coincides with a special event trigger, the write operation will take precedence. 14.8 timer1 gate timer1 can be configured to count freely or the count can be enabled and disabled using the timer1 gate circuitry. this is also referred to as timer1 gate count enable. timer1 gate can also be driven by multiple selectable sources. 14.8.1 timer1 gate count enable the timer1 gate enable mode is enabled by setting the tmr1ge bit of the t1gcon register. the polarity of the timer1 gate enable mode is configured using the t1gpol bit (t1gcon<6>). when timer1 gate enable mode is enabled, timer1 will increment on the rising edge of the timer1 clock source. when timer1 gate enable mode is disabled, no incrementing will occur and timer1 will hold the current count. see figure 14-4 for timing details. table 14-3: timer1 gate enable selections note: the special event trigger from the eccp module will only clear the tmr1 register?s content, but not set the tmr1if interrupt flag bit (pir1<0>). t1clk (?) t1gpol (t1gcon<6>) t1g pin timer1 operation ? 00 counts ? 01 holds count ? 10 holds count ? 11 counts ? the clock on which tmr1 is running. for more information, see figure 14-1 . note: the ccp and eccp modules use timers, 1 through 4, for some modes. the assign- ment of a particular timer to a ccp/eccp module is determined by the timer to ccp enable bits in the ccptmrs register. for more details, see register 20-2 and register 19-2 .
? 2011 microchip technology inc. ds39977d-page 221 pic18f66k80 family figure 14-4: timer1 gate count enable mode 14.8.2 timer1 gate source selection the timer1 gate source can be selected from one of four sources. source selection is controlled by the t1gssx (t1gcon<1:0>) bits (see table 14-4 ). table 14-4: timer1 gate sources the polarity for each available source is also selectable, controlled by the t1gpol bit (t1gcon<6>). 14.8.2.1 t1g pin gate operation the t1g pin is one source for timer1 gate control. it can be used to supply an external source to the timer1 gate circuitry. 14.8.2.2 timer2 match gate operation the tmr2 register will increment until it matches the value in the pr2 register. on the very next increment cycle, tmr2 will be reset to 00h. when this reset occurs, a low-to-high pulse will automatically be gener- ated and internally supplied to the timer1 gate circuitry. the pulse will remain high for one instruction cycle and will return back to a low state until the next match. depending on t1gpol, timer1 increments differently when tmr2 matches pr2. when t1gpol = 1 , timer1 increments for a single instruction cycle following a tmr2 match with pr2. when t1gpol = 0 , timer1 increments continuously except for the cycle following the match when the gate signal goes from low-to-high. 14.8.2.3 comparator 1 output gate operation the output of comparator 1 can be internally supplied to the timer1 gate circuitry. after setting up comparator 1 with the cm1con register, timer1 will increment depending on the transitions of the cmp1out (cmstat<6>) bit. 14.8.2.4 comparator 2 output gate operation the output of comparator 2 can be internally supplied to the timer1 gate circuitry. after setting up comparator 2 with the cm2con register, timer1 will increment depending on the transitions of the cmp2out (cmstat<7>) bit. tmr1ge t1gpol t1g_in t1cki t1gval timer1 n n + 1 n + 2 n + 3 n + 4 t1gss<1:0> timer1 gate source 00 timer1 gate pin 01 tmr2 to match pr2 (tmr2 increments to match pr2) 10 comparator 1 output (comparator logic high output) 11 comparator 2 output (comparator logic high output)
pic18f66k80 family ds39977d-page 222 ? 2011 microchip technology inc. 14.8.3 timer1 gate toggle mode when timer1 gate toggle mode is enabled, it is possible to measure the full cycle length of a timer1 gate signal, as opposed to the duration of a single level pulse. the timer1 gate source is routed through a flip-flop that changes state on every incrementing edge of the signal. (for timing details, see figure 14-5 .) the t1gval bit (t1gcon<2>) indicates when the toggled mode is active and the timer is counting. the timer1 gate toggle mode is enabled by setting the t1gtm bit (t1gcon<5>). when t1gtm is cleared, the flip-flop is cleared and held clear. this is necessary in order to control which edge is measured. figure 14-5: timer1 gate toggle mode tmr1ge t1gpol t1gtm t1g_in t1cki t1gval timer1 n n + 1 n + 2 n + 3 n + 4 n + 5 n + 6 n + 7 n + 8
? 2011 microchip technology inc. ds39977d-page 223 pic18f66k80 family 14.8.4 timer1 gate single pulse mode when timer1 gate single pulse mode is enabled, it is possible to capture a single pulse gate event. timer1 gate single pulse mode is enabled by setting the t1gspm bit (t1gcon<4>) and the t1ggo/t1done bit (t1gcon<3>). the timer1 will be fully enabled on the next incrementing edge. on the next trailing edge of the pulse, the t1ggo/ t1done bit will automatically be cleared. no other gate events will be allowed to increment timer1 until the t1ggo/t1done bit is once again set in software. clearing the t1gspm bit of the t1gcon register will also clear the t1ggo/t1done bit. (for timing details, see figure 14-6 .) simultaneously enabling the toggle and single pulse modes will permit both sections to work together. this allows the cycle times on the timer1 gate source to be measured. (for timing details, see figure 14-7 .) 14.8.5 timer1 gate value status when the timer1 gate value status is utilized, it is possible to read the most current level of the gate control value. the value is stored in the t1gval bit (t1gcon<2>). this bit is valid even when the timer1 gate is not enabled (tmr1ge bit is cleared). figure 14-6: timer1 gate single pulse mode tmr1ge t1gpol t1g_in t1cki t1gval timer1 n n + 1 n + 2 t1gspm t1ggo/ t1done set by software cleared by hardware on falling edge of t1gval counting enabled on rising edge of t1g
pic18f66k80 family ds39977d-page 224 ? 2011 microchip technology inc. figure 14-7: timer1 gate single pulse and toggle combined mode table 14-5: registers associated with timer1 as a timer/counter name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif pir1 pspif adif rc1if tx1if sspif tmr1gif tmr2if tmr1if pie1 pspie adie rc1ie tx1ie sspie tmr1gie tmr2ie tmr1ie ipr1 pspip adip rc1ip tx1ip sspip tmr1gip tmr2ip tmr1ip tmr1l timer1 register low byte tmr1h timer1 register high byte t1con tmr1cs1 tmr1cs0 t1ckps1 t1ckps0 soscen t1sync rd16 tmr1on t1gcon tmr1ge t1gpol t1gtm t1gspm t1ggo/ t1done t1gval t1gss1 t1gss0 osccon2 ? soscrun ? soscdrv soscgo ? mfiofs mfiosel pmd1 pspmd ctmumd adcmd tmr4md tmr3md tmr2md tmr1md tmr0md legend: shaded cells are not used by the timer1 module. tmr1ge t1gpol t1g_in t1cki t1gval timer1 n n + 1 n + 2 t1gspm t1ggo/ t1do ne set by software cleared by hardware on falling edge of t1gval t1gtm counting enabled on rising edge of t1g n + 4 n + 3
? 2011 microchip technology inc. ds39977d-page 225 pic18f66k80 family 15.0 timer2 module the timer2 module incorporates the following features: ? eight-bit timer and period registers (tmr2 and pr2, respectively) ? both registers are readable and writable ? software programmable prescaler (1:1, 1:4 and 1:16) ? software programmable postscaler (1:1 through 1:16) ? interrupt on tmr2 to pr2 match ? optional use as the shift clock for the mssp module the module is controlled through the t2con register ( register 15-1 ) that enables or disables the timer, and configures the prescaler and postscaler. timer2 can be shut off by clearing control bit, tmr2on (t2con<2>), to minimize power consumption. a simplified block diagram of the module is shown in figure 15-1 . 15.1 timer2 operation in normal operation, tmr2 is incremented from 00h on each clock (f osc /4). a four-bit counter/prescaler on the clock input gives the prescale options of direct input, divide-by-4 or divide-by-16. these are selected by the prescaler control bits, t2ckps<1:0> (t2con<1:0>). the value of tmr2 is compared to that of the period reg- ister, pr2, on each clock cycle. when the two values match, the comparator generates a match signal as the timer output. this signal also resets the value of tmr2 to 00h on the next cycle and drives the output counter/ postscaler. (see section 15.2 ?timer2 interrupt? .) the tmr2 and pr2 registers are both directly readable and writable. the tmr2 register is cleared on any device reset, while the pr2 register initializes at ffh. both the prescaler and postscaler counters are cleared on the following events: ? a write to the tmr2 register ? a write to the t2con register ? any device reset ? power-on reset (por), mclr reset, watchdog timer reset (wdtr) or brown-out reset (bor) tmr2 is not cleared when t2con is written. note: the ccp and eccp modules use timers, 1 through 4, for some modes. the assign- ment of a particular timer to a ccp/eccp module is determined by the timer to ccp enable bits in the ccptmrs register. for more details, see register 20-2 and register 19-2 . register 15-1: t2con: ti mer2 control register u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? t2outps3 t2outps2 t2outps1 t2outps0 tmr2on t2ckps1 t2ckps0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-3 t2outps<3:0>: timer2 output postscale select bits 0000 = 1:1 postscale 0001 = 1:2 postscale ? ? ? 1111 = 1:16 postscale bit 2 tmr2on: timer2 on bit 1 = timer2 is on 0 = timer2 is off bit 1-0 t2ckps<1:0>: timer2 clock prescale select bits 00 = prescaler is 1 01 = prescaler is 4 1x = prescaler is 16
pic18f66k80 family ds39977d-page 226 ? 2011 microchip technology inc. 15.2 timer2 interrupt timer2 can also generate an optional device interrupt. the timer2 output signal (tmr2 to pr2 match) provides the input for the four-bit output counter/postscaler. this counter generates the tmr2 match interrupt flag, which is latched in tmr2if (pir1<1>). the interrupt is enabled by setting the tmr2 match interrupt enable bit, tmr2ie (pie1<1>). a range of 16 postscaler options (from 1:1 through 1:16 inclusive) can be selected with the postscaler control bits, t2outps<3:0> (t2con<6:3>). 15.3 timer2 output the unscaled output of tmr2 is available primarily to the eccp modules, where it is used as a time base for operations in pwm mode. timer2 can optionally be used as the shift clock source for the mssp module operating in spi mode. additional information is provided in section 21.0 ?master synchronous serial port (mssp) module? . figure 15-1: timer2 block diagram table 15-1: registers associated with timer2 as a timer/counter name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif pir1 pspif adif rc1if tx1if sspif tmr1gif tmr2if tmr1if pie1 pspie adie rc1ie tx1ie sspie tmr1gie tmr2ie tmr1ie ipr1 pspip adip rc1ip tx1ip sspip tmr1gip tmr2ip tmr1ip tmr2 timer2 register t2con ? t2outps3 t2outps2 t2outps1 t2outps0 tmr2on t2ckps1 t2ckps0 pr2 timer2 period register pmd1 pspmd ctmumd adcmd tmr4md tmr3md tmr2md tmr1md tmr0md legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the timer2 module. comparator tmr2 output tmr2 postscaler prescaler pr2 2 f osc /4 1:1 to 1:16 1:1, 1:4, 1:16 4 t2outps<3:0> t2ckps<1:0> set tmr2if internal data bus 8 reset tmr2/pr2 8 8 (to pwm or mssp) match
? 2011 microchip technology inc. ds39977d-page 227 pic18f66k80 family 16.0 timer3 module the timer3 timer/counter modules incorporate these features: ? software selectable operation as a 16-bit timer or counter ? readable and writable eight-bit registers (tmr3h and tmr3l) ? selectable clock source (internal or external) with device clock or sosc oscillator internal options ? interrupt-on-overflow ? module reset on eccp special event trigger a simplified block diagram of the timer3 module is shown in figure 16-1 . the timer3 module is controlled through the t3con register ( register 16-1 ). it also selects the clock source options for the eccp modules. (for more information, see section 20.1.1 ?eccp module and timer resources? .) the f osc clock source should not be used with the eccp capture/compare features. if the timer will be used with the capture or compare features, always select one of the other timer clocking options. register 16-1: t3con: ti mer3 control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 tmr3cs1 tmr3cs0 t3ckps1 t3ckps0 soscen t3sync rd16 tmr3on bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 tmr3cs<1:0>: timer3 clock source select bits 10 = timer3 clock source is either from pin or oscillator, depending on the soscen bit: soscen = 0 : external clock is from t3cki pin (on the rising edge). soscen = 1 : depending on the soscsel configuration bit, the clock source is either a crystal oscillator on sosci/sosco or an internal digital clock from the sclki pin. 01 = timerx clock source is system clock (f osc ) (1) 00 = timerx clock source is instruction clock (f osc /4) bit 5-4 t3ckps<1:0> : timer3 input clock prescale select bits 11 = 1:8 prescale value 10 = 1:4 prescale value 01 = 1:2 prescale value 00 = 1:1 prescale value bit 3 soscen : sosc oscillator enable bit 1 = sosc enabled and available for timer3 0 = sosc disabled and available for timer3 bit 2 t3sync : timer3 external clock input synchronization control bit (not usable if the device clock comes from timer1/timer3.) when tmr 3c s<1:0> = 10 : 1 = do not synchronize external clock input 0 = synchronize external clock input when tmr 3c s<1:0> = 0x : this bit is ignored; timer3 uses the internal clock. bit 1 rd16: 16-bit read/write mode enable bit 1 = enables register read/write of timer3 in one 16-bit operation 0 = enables register read/write of timer3 in two eight-bit operations bit 0 tmr3on: timer3 on bit 1 = enables timer3 0 = stops timer3 note 1: the f osc clock source should not be selected if the timer w ill be used with the eccp capture/compare features.
pic18f66k80 family ds39977d-page 228 ? 2011 microchip technology inc. 16.1 timer3 gate control register the timer3 gate control register (t3gcon), provided in register 14-2, is used to control the timer3 gate. register 16-2: t3gcon: timer3 gate control register (1) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-x r/w-0 r/w-0 tmr3ge t3gpol t3gtm t3gspm t3ggo/t3done t3gval t3gss1 t3gss0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 tmr3ge: timer3 gate enable bit if tmr 3o n = 0 : this bit is ignored. if tmr 3o n = 1 : 1 = timer3 counting is controlled by the timer3 gate function 0 = timer3 counts regardless of timer3 gate function bit 6 t3gpol: timer3 gate polarity bit 1 = timer3 gate is active-high (timer3 counts when gate is high) 0 = timer3 gate is active-low (timer3 counts when gate is low) bit 5 t3gtm: timer3 gate toggle mode bit 1 = timer3 gate toggle mode is enabled. 0 = timer3 gate toggle mode is disabled and toggle flip-flop is cleared timer3 gate flip-flop toggles on every rising edge. bit 4 t3gspm: timerx gate single pulse mode bit 1 = timer3 gate single pulse mode is enabled and is controlling timer3 gate 0 = timer3 gate single pulse mode is disabled bit 3 t3ggo/t3done : timer3 gate single pulse acquisition status bit 1 = timer3 gate single pulse acquisition is ready, waiting for an edge 0 = timer3 gate single pulse acquisition has completed or has not been started this bit is automatically cleared when t3gspm is cleared. bit 2 t3gval: timer3 gate current state bit indicates the current state of the timerx gate that could be provided to tmr3h:tmr3l. unaffected by timerx gate enable (tmr3ge) bit. bit 1-0 t3gss<1:0>: timer3 gate source select bits 11 = comparator 2 output 10 = comparator 1 output 01 = tmr4 to match pr4 output 00 = timer3 gate pin watchdog timer oscillator is turned on if tmr3ge = 1 , regardless of the state of tmr3on. note 1: programming the t3gcon prior to t3con is recommended.
? 2011 microchip technology inc. ds39977d-page 229 pic18f66k80 family register 16-3: osccon2: osci llator control register 2 u-0 r-0 u-0 rw-0 r/w-0 u-0 r-0 r/w-0 ? soscrun ?soscdrv (1) soscgo ? mfiofs mfiosel bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 soscrun: sosc run status bit 1 = system clock comes from a secondary sosc 0 = system clock comes from an oscillator other than sosc bit 5 unimplemented: read as ? 0 ? bit 4 soscdrv: secondary oscillator drive control bit (1) 1 = high-power sosc circuit selected 0 = low/high-power select is done via the soscsel<1:0> configuration bits bit 3 soscgo: oscillator start control bit 1 = oscillator is running even if no other sources are requesting it 0 = oscillator is shut off if no other sources are requesting it (when the sosc is selected to run from a digital clock input, rather than an external crystal, this bit has no effect.) bit 2 unimplemented: read as ? 0 ? bit 1 mfiofs: mf-intosc frequency stable bit 1 = mf-intosc is stable 0 = mf-intosc is not stable bit 0 mfiosel: mf-intosc select bit 1 = mf-intosc is used in place of hf-intosc frequencies of 500 khz, 250 khz and 31.25 khz 0 = mf-intosc is not used note 1: when sosc is selected to run from a digital clock input, rather than an external crystal, this bit has no effect.
pic18f66k80 family ds39977d-page 230 ? 2011 microchip technology inc. 16.2 timer3 operation timer3 can operate in these modes: ?timer ? synchronous counter ? asynchronous counter ? timer with gated control the operating mode is determined by the clock select bits, tmr3csx (t3con<7:6>). when the tmr3csx bits are cleared (= 00 ), timer3 increments on every internal instruction cycle (f osc /4). when tmr3csx = 01 , the timer3 clock source is the system clock (f osc ), and when it is ? 10 ?, timer3 works as a counter from the external clock from the t3cki pin (on the rising edge after the first falling edge) or the sosc oscillator. figure 16-1: timer3 block diagram tmr3h tmr3l t3sync t3ckps<1:0> prescaler 1, 2, 4, 8 0 1 synchronized clock input 2 set flag bit, tmr3if, on overflow tmr3 (2) tmr3on note 1: st buffer is high-speed type when using t3cki. 2: timer3 registers increment on rising edge. 3: synchronization does not operate while in sleep. 4: the output of sosc is determined by the soscsel<1:0> configuration bits. t3g sosc f osc /4 internal clock sosco/sclki sosci 1 0 t3cki tmr3cs<1:0> (1) synchronize (3) det sleep input tmr3ge 0 1 00 01 10 11 from tmr4 from comparator 1 t3gpol d q ck q 0 1 t3gval t3gtm single pulse acq. control t3gspm t3ggo/t3done t3gss<1:0> en out (4) 10 00 01 f osc internal clock from comparator 2 output match pr4 r d en q q1 rd t3gcon data bus det interrupt tmr3gif set t3clk f osc /2 internal clock d en q t3g_in tmr3on output t1con.soscen t3con.soscen soscgo scs<1:0> = 01
? 2011 microchip technology inc. ds39977d-page 231 pic18f66k80 family 16.3 timer3 16-bit read/write mode timer3 can be configured for 16-bit reads and writes (see figure 16.3 ). when the rd16 control bit (t3con<1>) is set, the address for tmr3h is mapped to a buffer register for the high byte of timer3. a read from tmr3l will load the contents of the high byte of timer3 into the timer3 high byte buffer register. this provides users with the ability to accurately read all 16 bits of timer3 without having to determine whether a read of the high byte, followed by a read of the low byte, has become invalid due to a rollover between reads. a write to the high byte of timer3 must also take place through the tmr3h buffer register. the timer3 high byte is updated with the contents of tmr3h when a write occurs to tmr3l. this allows users to write all 16 bits to both the high and low bytes of timer3 at once. the high byte of timer3 is not directly readable or writable in this mode. all reads and writes must take place through the timer3 high byte buffer register. writes to tmr3h do not clear the timer3 prescaler. the prescaler is only cleared on writes to tmr3l. 16.4 using the sosc oscillator as the timer3 clock source the sosc internal oscillator may be used as the clock source for timer3. it can be enabled in one of these ways: ? setting the soscen bit in either the t1con or t3con register (txcon<3>) ? setting the soscgo bit in the osccon2 register (osccon2<3>) ? setting the scs bits to secondary clock source in the osccon register (osccon<1:0> = 01 ) the soscgo bit is used to warm up the sosc so that it is ready before any peripheral requests it. to use it as the timer3 clock source, the tmr3csx bits must also be set. as previously noted, this also config- ures timer3 to increment on every rising edge of the oscillator source. the sosc oscillator is described in section 14.5 ?sosc oscillator? .
pic18f66k80 family ds39977d-page 232 ? 2011 microchip technology inc. 16.5 timer3 gates timer3 can be configured to count freely or the count can be enabled and disabled using the timer3 gate circuitry. this is also referred to as the timer3 gate count enable. the timer3 gate can also be driven by multiple selectable sources. 16.5.1 timer3 gate count enable the timer3 gate enable mode is enabled by setting the tmr3ge bit (txgcon<7>). the polarity of the timer3 gate enable mode is configured using the t3gpol bit (t3gcon<6>). when timer3 gate enable mode is enabled, timer3 will increment on the rising edge of the timer3 clock source. when timer3 gate enable mode is disabled, no incre- menting will occur and timer3 will hold the current count. see figure 16-2 for timing details. table 16-1: timer3 gate enable selections figure 16-2: timer3 gate count enable mode t3clk (?) t3gpol (t3gcon<6>) t3g pin timer3 operation ? 00 counts ? 01 holds count ? 10 holds count ? 11 counts ? the clock on which tmr3 is running. for more information, see t3clk in figure 16-1 . tmr3ge t3gpol t3g_in t3cki t3gval timer3 n n + 1 n + 2 n + 3 n + 4
? 2011 microchip technology inc. ds39977d-page 233 pic18f66k80 family 16.5.2 timer3 gate source selection the timer3 gate source can be selected from one of four different sources. source selection is controlled by the t3gss<1:0> bits (t3gcon<1:0>). the polarity for each available source is also selectable and is controlled by the t3gpol bit (t3gcon<6>). table 16-2: timer3 gate sources 16.5.2.1 t3g pin gate operation the t3g pin is one source for timer3 gate control. it can be used to supply an external source to the timerx gate circuitry. 16.5.2.2 timer4 match gate operation the tmr4 register will increment until it matches the value in the pr4 register. on the very next increment cycle, tmr4 will be reset to 00h. when this reset occurs, a low-to-high pulse will automatically be gener- ated and internally supplied to the timerx gate circuitry. the pulse will remain high for one instruction cycle and will return back to a low state until the next match. depending on t3gpol, timerx increments differently when tmr4 matches pr4. when t3gpol = 1 , timer3 increments for a single instruction cycle following a tmr4 match with pr4. when t3gpol = 0 , timer3 increments continuously, except for the cycle following the match, when the gate signal goes from low-to-high. 16.5.2.3 comparator 1 output gate operation the output of comparator 1 can be internally supplied to the timer3 gate circuitry. after setting up comparator 1 with the cm1con register, timer3 will increment depending on the transitions of the cmp1out (cmstat<6>) bit. 16.5.2.4 comparator 2 output gate operation the output of comparator 2 can be internally supplied to the timer3 gate circuitry. after setting up comparator 2 with the cm2con register, timer3 will increment depending on the transitions of the cmp2out (cmstat<7>) bit. 16.5.3 timer3 gate toggle mode when timer3 gate toggle mode is enabled, it is possible to measure the full cycle length of a timer3 gate signal, as opposed to the duration of a single level pulse. the timer3 gate source is routed through a flip-flop that changes state on every incrementing edge of the signal. (for timing details, see figure 16-3 .) the t3gval bit will indicate when the toggled mode is active and the timer is counting. timer3 gate toggle mode is enabled by setting the t3gtm bit (t3gcon<5>). when the t3gtm bit is cleared, the flip-flop is cleared and held clear. this is necessary in order to control which edge is measured. figure 16-3: timer3 gate toggle mode t3gss<1:0> timer3 gate source 00 timerx gate pin 01 tmr4 to match pr4 (tmr4 increments to match pr4) 10 comparator 1 output (comparator logic high output) 11 comparator 2 output (comparator logic high output) tmr3ge t3gpol t3gtm t3g_in t3cki t3gval timer3 n n + 1 n + 2 n + 3 n + 4 n + 5 n + 6 n + 7 n + 8
pic18f66k80 family ds39977d-page 234 ? 2011 microchip technology inc. 16.5.4 timer3 gate single pulse mode when timer3 gate single pulse mode is enabled, it is possible to capture a single pulse gate event. timer3 gate single pulse mode is first enabled by setting the t3gspm bit (t3gcon<4>). next, the t3ggo/ t 3d one bit (t3gcon<3>) must be set. the timer3 will be fully enabled on the next increment- ing edge. on the next trailing edge of the pulse, the t3ggo/t 3d one bit will automatically be cleared. no other gate events will be allowed to increment timer3 until the t3ggo/t 3d one bit is once again set in software. clearing the t3gspm bit will also clear the t3ggo/ t 3d one bit. (for timing details, see figure 16-4 .) simultaneously enabling the toggle mode and the single pulse mode will permit both sections to work together. this allows the cycle times on the timer3 gate source to be measured. (for timing details, see figure 16-5 .) figure 16-4: timer3 gate single pulse mode tmr3ge t3gpol t3g_in t3cki t3gval timer3 n n + 1 n + 2 t3gspm t3ggo/ t3done set by software cleared by hardware on falling edge of t3gval set by hardware on falling edge of t3gval cleared by software cleared by software tmr3gif counting enabled on rising edge of t3g
? 2011 microchip technology inc. ds39977d-page 235 pic18f66k80 family figure 16-5: timer3 gate single pulse and toggle combined mode 16.5.5 timer3 gate value status when timer3 gate value status is utilized, it is possible to read the most current level of the gate control value. the value is stored in the t3gval bit (t3gcon<2>). the t3gval bit is valid even when the timer3 gate is not enabled (tmr3ge bit is cleared). 16.5.6 timer3 gate event interrupt when the timer3 gate event interrupt is enabled, it is possible to generate an interrupt upon the completion of a gate event. when the falling edge of t3gval occurs, the tmr3gif flag bit in the pir2 register will be set. if the tmr3gie bit in the pie2 register is set, then an interrupt will be recognized. the tmr3gif flag bit operates even when the timer3 gate is not enabled (tmr3ge bit is cleared). tmr3ge t3gpol t3g_in t3cki t3gval timer3 n n + 1 n + 2 t3gspm t3ggo/ t3done set by software cleared by hardware on falling edge of t3gval set by hardware on falling edge of t3gval cleared by software cleared by software tmr3gif t3gtm counting enabled on rising edge of t3g n + 4 n + 3
pic18f66k80 family ds39977d-page 236 ? 2011 microchip technology inc. 16.6 timer3 interrupt the tmr3 register pair (tmr3h:tmr3l) increments from 0000h to ffffh and overflows to 0000h. the timer3 interrupt, if enabled, is generated on overflow and is latched in the interrupt flag bit, tmr3if. table 16-3 gives each module?s flag bit. this interrupt can be enabled or disabled by setting or clearing the tmr3ie bit. table 16-3 displays each module?s enable bit. 16.7 resetting timer3 using the eccp special event trigger if the eccp modules are configured to use timer3 and to generate a special event trigger in compare mode (ccp3m<3:0> = 1011 ), this signal will reset timer3. the trigger from eccp will also start an a/d conversion if the a/d module is enabled (for more information, see section 20.3.4 ?special event trigger? .) the module must be configured as either a timer or synchronous counter to take advantage of this feature. when used this way, the ccpr3h:ccpr3l register pair effectively becomes a period register for timer3. if timer3 is running in asynchronous counter mode, the reset operation may not work. in the event that a write to timer3 coincides with a special event trigger from an eccp module, the write will take precedence. table 16-3: registers associated with timer3 as a timer/counter note: the special event triggers from the eccpx module will only clear the tmr3 register?s content, but not set the tmr3if interrupt flag bit (pir2<1>). note: the ccp and eccp modules use timers, 1 through 4, for some modes. the assign- ment of a particular timer to a ccp/eccp module is determined by the timer to ccp enable bits in the ccptmrs register. for more details, see register 20-2 and register 19-2 . name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif pir5 irxif wakif errif txb2if txb1if txb0if rxb1if rxb0if pie5 irxie wakie errie tx2bie txb1ie txb0ie rxb1ie rxb0ie pir2 oscfif ? ? ? bclif hlvdif tmr3if tmr3gif pie2 oscfie ? ? ? bclie hlvdie tmr3ie tmr3gie tmr3h timer3 register high byte tmr3l timer3 register low byte t3gcon tmr3ge t3gpol t3gtm t3gspm t3ggo/ t3done t3gval t3gss1 t3gss0 t3con tmr3cs1 tmr3cs0 t3ckps1 t3ckps0 soscen t3sync rd16 tmr3on osccon2 ? soscrun ? soscdrv soscgo ? mfiofs mfiosel pmd1 pspmd ctmumd adcmd tmr4md tmr3md tmr2md tmr1md tmr0md legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the timer3 module.
? 2011 microchip technology inc. ds39977d-page 237 pic18f66k80 family 17.0 timer4 modules the timer4 timer modules have the following features: ? eight-bit timer register (tmr4) ? eight-bit period register (pr4) ? readable and writable (all registers) ? software programmable prescaler (1:1, 1:4, 1:16) ? software programmable postscaler (1:1 to 1:16) ? interrupt on tmr4 match of pr4 the timer4 modules have a control register shown in register 17-1 . timer4 can be shut off by clearing control bit, tmr4on (t4con<2>), to minimize power consumption. the prescaler and postscaler selection of timer4 also are controlled by this register. figure 17-1 is a simplified block diagram of the timer4 modules. 17.1 timer4 operation timer4 can be used as the pwm time base for the pwm mode of the eccp modules. the tmr4 registers are readable and writable, and are cleared on any device reset. the input clock (f osc /4) has a prescale option of 1:1, 1:4 or 1:16, selected by control bits, t4ckps<1:0> (t4con<1:0>). the match output of tmr4 goes through a four-bit postscaler (that gives a 1:1 to 1:16 inclusive scaling) to generate a tmr4 interrupt, latched in the flag bit, tmr4if. tab l e 1 7- 1 gives each module?s flag bit. the interrupt can be enabled or disabled by setting or clearing the timer4 interrupt enable bit (tmr4ie), shown in tab l e 1 7- 1 . the prescaler and postscaler counters are cleared when any of the following occurs: ? a write to the tmr4 register ? a write to the t4con register ? any device reset ? power-on reset (por), mclr reset, watchdog timer reset (wdtr) or brown-out reset (bor) a tmr4 is not cleared when a t4con is written. note: the ccp and eccp modules use timers, 1 through 4, for some modes. the assign- ment of a particular timer to a ccp/eccp module is determined by the timer to ccp enable bits in the ccptmrs register. for more details, see register 20-2 and register 19-2 . register 17-1: t4con: ti mer4 control register u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? t4outps3 t4outps2 t4outps1 t4outps0 tmr4on t4ckps1 t4ckps0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-3 t4outps<3:0>: timer4 output postscale select bits 0000 = 1:1 postscale 0001 = 1:2 postscale ? ? ? 1111 = 1:16 postscale bit 2 tmr4on : timer4 on bit 1 = timer4 is on 0 = timer4 is off bit 1-0 t4ckps<1:0>: timer4 clock prescale select bits 00 = prescaler is 1 01 = prescaler is 4 1x = prescaler is 16
pic18f66k80 family ds39977d-page 238 ? 2011 microchip technology inc. 17.2 timer4 interrupt the timer4 module has an eight-bit period register, pr4, that is both readable and writable. timer4 incre- ment from 00h until it matches pr4 and then resets to 00h on the next increment cycle. the pr4 register is initialized to ffh upon reset. 17.3 output of tmr4 the outputs of tmr4 (before the postscaler) are used only as a pwm time base for the eccp modules. they are not used as baud rate clocks for the mssp module as is the timer2 output. figure 17-1: timer4 block diagram table 17-1: registers associated with timer4 as a timer/counter name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif ipr4 tmr4ip eeip cmp2ip cmp1ip ? ccp5ip ccp4ip ccp3ip pir4 tmr4if eeif cmp2if cmp1if ? ccp5if ccp4if ccp3if pie4 tmr4ie eeie cmp2ie cmp1ie ? ccp5ie ccp4ie ccp3ie tmr4 timer4 register t4con ? t4outps3 t4outps2 t4outps1 t4outps0 tmr4on t4ckps1 t4ckps0 pr4 timer4 period register pmd1 pspmd ctmumd adcmd tmr4md tmr3md tmr2md tmr1md tmr0md legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the timer4 module. comparator tmr4 output tmr4 postscaler prescaler pr4 2 f osc /4 1:1 to 1:16 1:1, 1:4, 1:16 4 t4outps<3:0> t4ckps<1:0> set tmr4if internal data bus 8 reset tmrx/prx 8 8 (to pwm) match
? 2011 microchip technology inc. ds39977d-page 239 pic18f66k80 family 18.0 charge time measurement unit (ctmu) the charge time measurement unit (ctmu) is a flexible analog module that provides accurate differen- tial time measurement between pulse sources, as well as asynchronous pulse generation. by working with other on-chip analog modules, the ctmu can precisely measure time, capacitance and relative changes in capacitance or generate output pulses with a specific time delay. the ctmu is ideal for interfacing with capacitive-based sensors. the module includes these key features: ? up to 11 channels available for capacitive or time measurement input ? low-cost temperature measurement using on-chip diode channel ? on-chip precision current source ? four-edge input trigger sources ? polarity control for each edge source ? control of edge sequence ? control of response to edges ? time measurement resolution of 1 nanosecond ? high-precision time measurement ? time delay of external or internal signal asynchronous to system clock ? accurate current source suitable for capacitive measurement the ctmu works in conjunction with the a/d converter to provide up to 11 channels for time or charge measurement, depending on the specific device and the number of a/d channels available. when config- ured for time delay, the ctmu is connected to one of the analog comparators. the level-sensitive input edge sources can be selected from four sources: two external inputs or the eccp1/ccp2 special event triggers. the ctmu special event can trigger the analog-to-digital converter module. figure 18-1 provides a block diagram of the ctmu. figure 18-1: ctmu block diagram cted1 cted2 current source edge control logic ctmuconh:ctmuconl pulse generator a/d converter comparator 2 input ccp2 eccp1 current control itrim<5:0> irng<1:0> ctmuicon ctmu control logic edgen edgseqen edg1sel<1:0> edg1pol edg2sel<1:0> edg2pol edg1stat edg2stat tgen idissen cttrig a/d trigger ctpls comparator 2 output
pic18f66k80 family ds39977d-page 240 ? 2011 microchip technology inc. 18.1 ctmu registers the control registers for the ctmu are: ? ctmuconh ? ctmuconl ? ctmuicon the ctmuconh and ctmuconl registers ( register 18-1 and register 18-2 ) contain control bits for configuring the ctmu module edge source selec- tion, edge source polarity selection, edge sequencing, a/d trigger, analog circuit capacitor discharge and enables. the ctmuicon register ( register 18-3 ) has bits for selecting the current source range and current source trim. register 18-1: ctmuconh: ct mu control high register r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ctmuen ? ctmusidl tgen edgen edgseqen idissen cttrig bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ctmuen: ctmu enable bit 1 = module is enabled 0 = module is disabled bit 6 unimplemented: read as ? 0 ? bit 5 ctmusidl: stop in idle mode bit 1 = discontinue module operation when device enters idle mode 0 = continue module operation in idle mode bit 4 tgen: time generation enable bit 1 = enables edge delay generation 0 = disables edge delay generation bit 3 edgen: edge enable bit 1 = edges are not blocked 0 = edges are blocked bit 2 esgseqen: edge sequence enable bit 1 = edge 1 event must occur before edge 2 event can occur 0 = no edge sequence is needed bit 1 idissen: analog current source control bit 1 = analog current source output is grounded 0 = analog current source output is not grounded bit 0 cttrig: ctmu special event trigger bit 1 = ctmu special event trigger is enabled 0 = ctmu special event trigger is disabled
? 2011 microchip technology inc. ds39977d-page 241 pic18f66k80 family register 18-2: ctmuconl: ct mu control low register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 edg2pol edg2sel1 edg2sel0 edg1pol ed g1sel1 edg1sel0 edg2stat edg1stat bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 edg2pol: edge 2 polarity select bit 1 = edge 2 programmed for a positive edge response 0 = edge 2 programmed for a negative edge response bit 6-5 edg2sel<1:0>: edge 2 source select bits 11 = cted1 pin 10 = cted2 pin 01 = eccp1 special event trigger 00 = ccp2 special event trigger bit 4 edg1pol: edge 1 polarity select bit 1 = edge 1 programmed for a positive edge response 0 = edge 1 programmed for a negative edge response bit 3-2 edg1sel<1:0>: edge 1 source select bits 11 = cted1 pin 10 = cted2 pin 01 = eccp1 special event trigger 00 = ccp2 special event trigger bit 1 edg2stat: edge 2 status bit 1 = edge 2 event has occurred 0 = edge 2 event has not occurred bit 0 edg1stat: edge 1 status bit 1 = edge 1 event has occurred 0 = edge 1 event has not occurred
pic18f66k80 family ds39977d-page 242 ? 2011 microchip technology inc. register 18-3: ctmuicon: ctmu current control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 itrim5 itrim4 itrim3 itrim2 itrim1 itrim0 irng1 irng0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-2 itrim<5:0>: current source trim bits 011111 = maximum positive change (+62% typ.) from nominal current 011110 . . . 000001 = minimum positive change (+2% typ.) from nominal current 000000 = nominal current output specified by irng<1:0> 111111 = minimum negative change (-2% typ.) from nominal current . . . 100010 100001 = maximum negative change (-62% typ.) from nominal current bit 1-0 irng<1:0>: current source range select bits 11 = 100 x base current 10 = 10 x base current 01 = base current level (0.55 ? a nominal) 00 = current source disabled
? 2011 microchip technology inc. ds39977d-page 243 pic18f66k80 family 18.2 ctmu operation the ctmu works by using a fixed current source to charge a circuit. the type of circuit depends on the type of measurement being made. in the case of charge measurement, the current is fixed and the amount of time the current is applied to the cir- cuit is fixed. the amount of voltage read by the a/d becomes a measurement of the circuit?s capacitance. in the case of time measurement, the current, as well as the capacitance of the circuit, is fixed. in this case, the voltage read by the a/d is representative of the amount of time elapsed from the time the current source starts and stops charging the circuit. if the ctmu is being used as a time delay, both capaci- tance and current source are fixed, as well as the voltage supplied to the comparator circuit. the delay of a signal is determined by the amount of time it takes the voltage to charge to the comparator threshold voltage. 18.2.1 theory of operation the operation of the ctmu is based on the equation for charge: more simply, the amount of charge measured in coulombs in a circuit is defined as current in amperes ( i ) multiplied by the amount of time in seconds that the current flows ( t ). charge is also defined as the capaci- tance in farads ( c ) multiplied by the voltage of the circuit ( v ). it follows that: the ctmu module provides a constant, known current source. the a/d converter is used to measure ( v ) in the equation, leaving two unknowns: capacitance ( c ) and time ( t ). the above equation can be used to calcu- late capacitance or time, by either the relationship using the known fixed capacitance of the circuit: or by: using a fixed time that the current source is applied to the circuit. 18.2.2 current source at the heart of the ctmu is a precision current source, designed to provide a constant reference for measure- ments. the level of current is user-selectable across three ranges, or a total of two orders of magnitude, with the ability to trim the output in 2% increments (nominal). the current range is selected by the irng<1:0> bits (ctmuicon<1:0>), with a value of ? 01 ? representing the lowest range. current trim is provided by the itrim<5:0> bits (ctmuicon<7:2>). these six bits allow trimming of the current source in steps of approximately 2% per step. half of the range adjusts the current source posi- tively and the other half reduces the current source. a value of ? 000000 ? is the neutral position (no change). a value of ? 100001 ? is the maximum negative adjustment (approximately -62%) and ? 011111 ? is the maximum positive adjustment (approximately +62%). 18.2.3 edge selection and control ctmu measurements are controlled by edge events occurring on the module?s two input channels. each channel, referred to as edge 1 and edge 2, can be con- figured to receive input pulses from one of the edge input pins (cted1 and cted2) or ccpx special event triggers (eccp1 and ccp2). the input channels are level-sensitive, responding to the instantaneous level on the channel rather than a transition between levels. the inputs are selected using the edg1sel and edg2sel bit pairs (ctmuconl<3:2>, 6:5>). in addition to source, each channel can be configured for event polarity using the edge2pol and edge1pol bits (ctmuconl<7,4>). the input channels can also be filtered for an edge event sequence (edge 1 occur- ring before edge 2) by setting the edgseqen bit (ctmuconh<2>). 18.2.4 edge status the ctmuconl register also contains two status bits, edg2stat and edg1stat (ctmuconl<1:0>). their primary function is to show if an edge response has occurred on the corresponding channel. the ctmu automatically sets a particular bit when an edge response is detected on its channel. the level-sensitive nature of the input channels also means that the status bits become set immediately if the channel?s configura- tion is changed and matches the channel?s current state. the module uses the edge status bits to control the cur- rent source output to external analog modules (such as the a/d converter). current is only supplied to external modules when only one (not both) of the status bits is set. current is shut off when both bits are either set or cleared. this allows the ctmu to measure current only during the interval between edges. after both status bits are set, it is necessary to clear them before another measurement is taken. both bits should be cleared simultaneously, if possible, to avoid re-enabling the ctmu current source. in addition to being set by the ctmu hardware, the edge status bits can also be set by software. this per- mits a user application to manually enable or disable the current source. setting either (but not both) of the bits enables the current source. setting or clearing both bits at once disables the source. i = c ? dv dt i ? t = c ? v t = (c ? v)/i c = (i ? t)/v
pic18f66k80 family ds39977d-page 244 ? 2011 microchip technology inc. 18.2.5 interrupts the ctmu sets its interrupt flag (pir3<3>) whenever the current source is enabled, then disabled. an inter- rupt is generated only if the corresponding interrupt enable bit (pie3<3>) is also set. if edge sequencing is not enabled (i.e., edge 1 must occur before edge 2), it is necessary to monitor the edge status bits and determine which edge occurred last and caused the interrupt. 18.3 ctmu module initialization the following sequence is a general guideline used to initialize the ctmu module: 1. select the current source range using the irngx bits (ctmuicon<1:0>). 2. adjust the current source trim using the itrimx bits (ctmuicon<7:2>). 3. configure the edge input sources for edge 1 and edge 2 by setting the edg1sel and edg2sel bits (ctmuconl<3:2> and <6:5>, respectively). 4. configure the input polarities for the edge inputs using the edg1pol and edg2pol bits (ctmuconl<4,7>). the default configuration is for negative edge polarity (high-to-low transitions). 5. enable edge sequencing using the edgseqen bit (ctmuconh<2>). by default, edge sequencing is disabled. 6. select the operating mode (measurement or time delay) with the tgen bit (ctmuconh<4>). the default mode is time/capacitance measurement. 7. configure the module to automatically trigger an a/d conversion when the second edge event has occurred using the cttrig bit (ctmuconh<0>). the conversion trigger is disabled by default. 8. discharge the connected circuit by setting the idissen bit (ctmuconh<1>). 9. after waiting a sufficient time for the circuit to discharge, clear the idissen bit. 10. disable the module by clearing the ctmuen bit (ctmuconh<7>). 11. clear the edge status bits, edg2stat and edg1stat (ctmuconl<1:0>). both bits should be cleared simultaneously, if possible, to avoid re-enabling the ctmu current source. 12. enable both edge inputs by setting the edgen bit (ctmuconh<3>). 13. enable the module by setting the ctmuen bit. depending on the type of measurement or pulse generation being performed, one or more additional modules may also need to be initialized and configured with the ctmu module: ? edge source generation: in addition to the external edge input pins, eccp1/ccp2 special event triggers can be used as edge sources for the ctmu. ? capacitance or time measurement: the ctmu module uses the a/d converter to measure the voltage across a capacitor that is connected to one of the analog input channels. ? pulse generation: when generating system clock independent, output pulses, the ctmu module uses comparator 2 and the associated comparator voltage reference. 18.4 calibrating the ctmu module the ctmu requires calibration for precise measure- ments of capacitance and time, as well as for accurate time delay. if the application only requires measurement of a relative change in capacitance or time, calibration is usually not necessary. an example of a less precise application is a capacitive touch switch, in which the touch circuit has a baseline capacitance and the added capacitance of the human body changes the overall capacitance of a circuit. if actual capacitance or time measurement is required, two hardware calibrations must take place: ? the current source needs calibration to set it to a precise current. ? the circuit being measured needs calibration to measure or nullify any capacitance other than that to be measured. 18.4.1 current source calibration the current source on board the ctmu module has a range of 62% nominal for each of three current ranges. for precise measurements, it is possible to measure and adjust this current source by placing a high-precision resistor, r cal , onto an unused analog channel. an example circuit is shown in figure 18-2 . to measure the current source: 1. initialize the a/d converter. 2. initialize the ctmu. 3. enable the current source by setting edg1stat (ctmuconl<0>). 4. issue time delay for voltage across r cal to stabilize and adc sample/hold capacitor to charge. 5. perform the a/d conversion. 6. calculate the current source current using i=v/r cal , where r cal is a high-precision resistance and v is measured by performing an a/d conversion.
? 2011 microchip technology inc. ds39977d-page 245 pic18f66k80 family the ctmu current source may be trimmed with the trim bits in ctmuicon, using an iterative process to get the exact current desired. alternatively, the nominal value without adjustment may be used. that value may be stored by software, for use in all subsequent capacitive or time measurements. to calculate the optimal value for r cal , the nominal current must be chosen. for example, if the a/d converter reference voltage is 3.3v, use 70% of full scale (or 2.31v) as the desired approximate voltage to be read by the a/d converter. if the range of the ctmu current source is selected to be 0.55 ? a, the resistor value needed is calculated as r cal = 2.31v/0.55 ? a , for a value of 4.2 m ? . similarly, if the current source is chosen to be 5.5 ? a, r cal would be 420,000 ? , and 42,000 ? if the current source is set to 55 ? a. figure 18-2: ctmu current source calibration circuit a value of 70% of full-scale voltage is chosen to make sure that the a/d converter is in a range that is well above the noise floor. if an exact current is chosen to incorporate the trimming bits from ctmuicon, the resistor value of r cal may need to be adjusted accord- ingly. r cal also may be adjusted to allow for available resistor values. r cal should be of the highest precision available, in light of the precision needed for the circuit that the ctmu will be measuring. a recommended minimum would be 0.1% tolerance. the following examples show a typical method for performing a ctmu current calibration. ? example 18-1 demonstrates how to initialize the a/d converter and the ctmu. this routine is typical for applications using both modules. ? example 18-2 demonstrates one method for the actual calibration routine. this method manually triggers the a/d converter to demonstrate the entire step-wise process. it is also possible to automatically trigger the conversion by setting the ctmu?s cttrig bit (ctmuconh<0>). a/d converter ctmu anx r cal current source a/d trigger mux a/d pic18f66k80
pic18f66k80 family ds39977d-page 246 ? 2011 microchip technology inc. example 18-1: setup for ctmu calibration routines #include "p18cxxx.h" /**************************************************************************/ /*setup ctmu *****************************************************************/ /**************************************************************************/ void setup(void) { //ctmucon - ctmu control register ctmuconh = 0x00; //make sure ctmu is disabled ctmuconl = 0x90; //ctmu continues to run when emulator is stopped,ctmu continues //to run in idle mode,time generation mode disabled, edges are blocked //no edge sequence order, analog current source not grounded, trigger //output disabled, edge2 polarity = positive level, edge2 source = //source 0, edge1 polarity = positive level, edge1 source = source 0, // set edge status bits to zero //ctmuicon - ctmu current control register ctmuicon = 0x01; //0.55ua, nominal - no adjustment /**************************************************************************/ //setup ad converter; /**************************************************************************/ trisa=0x04; //set channel 2 as an input // configured an2 as an analog channel // ancon1 ancon1 = 0x04; // adcon1 adcon2bits.adfm=1; // result format 1= right justified adcon2bits.acqt=1; // acquisition time 7 = 20tad 2 = 4tad 1=2tad adcon2bits.adcs=2; // clock conversion bits 6= fosc/64 2=fosc/32 // adcon1 adcon1bits.vcfg0 =0; // vref+ = avdd adcon1bits.vcfg1 =0; // vref+ = avdd adcon1bits.vncfg = 0; // vref- = avss adcon1bits.chs=2; // select adc channel adcon0bits.adon=1; // turn on adc }
? 2011 microchip technology inc. ds39977d-page 247 pic18f66k80 family example 18-2: current calibration routine #include "p18cxxx.h" #define count 500 //@ 8mhz = 125us. #define delay for(i=0;i pic18f66k80 family ds39977d-page 248 ? 2011 microchip technology inc. 18.4.2 capacitance calibration there is a small amount of capacitance from the inter- nal a/d converter sample capacitor as well as stray capacitance from the circuit board traces and pads that affect the precision of capacitance measurements. a measurement of the stray capacitance can be taken by making sure the desired capacitance to be measured has been removed. after removing the capacitance to be measured: 1. initialize the a/d converter and the ctmu. 2. set edg1stat (= 1 ). 3. wait for a fixed delay of time, t . 4. clear edg1stat. 5. perform an a/d conversion. 6. calculate the stray and a/d sample capacitances: where: ? i is known from the current source measurement step ? t is a fixed delay ? v is measured by performing an a/d conversion this measured value is then stored and used for calculations of time measurement or subtracted for capacitance measurement. for calibration, it is expected that the capacitance of c stray + c ad is approximately known; c ad is approximately 4 pf. an iterative process may be required to adjust the time, t , that the circuit is charged to obtain a reasonable volt- age reading from the a/d converter. the value of t may be determined by setting c offset to a theoretical value and solving for t . for example, if c stray is theoretically calculated to be 11 pf, and v is expected to be 70% of v dd or 2.31v, t would be: or 63 ? s. see example 18-3 for a typical routine for ctmu capacitance calibration. c offset = c stray + c ad = (i ? t)/v (4 pf + 11 pf) ? 2.31v/0.55 ? a
? 2011 microchip technology inc. ds39977d-page 249 pic18f66k80 family example 18-3: capacitance calibration routine #include "p18cxxx.h" #define count 25 //@ 8mhz intfrc = 62.5 us. #define etime count*2.5 //time in us #define delay for(i=0;i pic18f66k80 family ds39977d-page 250 ? 2011 microchip technology inc. 18.5 measuring capacitance with the ctmu there are two ways to measure capacitance with the ctmu. the absolute method measures the actual capacitance value. the relative method only measures for any change in the capacitance. 18.5.1 absolute capacitance measurement for absolute capacitance measurements, both the current and capacitance calibration steps found in section 18.4 ?calibrating the ctmu module? should be followed. to perform these measurements: 1. initialize the a/d converter. 2. initialize the ctmu. 3. set edg1stat. 4. wait for a fixed delay, t . 5. clear edg1stat. 6. perform an a/d conversion. 7. calculate the total capacitance, c total = (i * t)/v , where: ? i is known from the current source measurement step ( section 18.4.1 ?current source calibration? ) ? t is a fixed delay ? v is measured by performing an a/d conversion 8. subtract the stray and a/d capacitance ( c offset from section 18.4.2 ?capacitance calibration? ) from c total to determine the measured capacitance. 18.5.2 capacitive touch sense using relative charge measurement not all applications require precise capacitance measurements. when detecting a valid press of a capacitance-based switch, only a relative change of capacitance needs to be detected. in such an application, when the switch is open (or not touched), the total capacitance is the capacitance of the combination of the board traces, the a/d converter and other elements. a larger voltage will be measured by the a/d converter. when the switch is closed (or touched), the total capacitance is larger due to the addition of the capacitance of the human body to the above listed capacitances and a smaller voltage will be measured by the a/d converter. to detect capacitance changes simply: 1. initialize the a/d converter and the ctmu. 2. set edg1stat. 3. wait for a fixed delay. 4. clear edg1stat. 5. perform an a/d conversion. the voltage measured by performing the a/d conver- sion is an indication of the relative capacitance. in this case, no calibration of the current source or circuit capacitance measurement is needed. (for a sample software routine for a capacitive touch switch, see example 18-4 .)
? 2011 microchip technology inc. ds39977d-page 251 pic18f66k80 family example 18-4: routine for capacitive touch switch #include "p18cxxx.h" #define count 500 //@ 8mhz = 125us. #define delay for(i=0;i opensw - trip + hyst) { switchstate = unpressed; } }
pic18f66k80 family ds39977d-page 252 ? 2011 microchip technology inc. 18.6 measuring time with the ctmu module time can be precisely measured after the ratio ( c/i ) is measured from the current and capacitance calibration step. to do that: 1. initialize the a/d converter and the ctmu. 2. set edg1stat. 3. set edg2stat. 4. perform an a/d conversion. 5. calculate the time between edges as t = (c/i) * v , where: ? i is calculated in the current calibration step ( section 18.4.1 ?current source calibration? ) ? c is calculated in the capacitance calibra- tion step ( section 18.4.2 ?capacitance calibration? ) ? v is measured by performing the a/d conversion it is assumed that the time measured is small enough that the capacitance, c ad + c ext , provides a valid voltage to the a/d converter. for the smallest time measurement, always set the a/d channel select bits chs<4:0> (adcon0<6:2>) to an unused a/d channel, the corresponding pin for which is not connected to any circuit board trace. this minimizes added stray capaci- tance, keeping the total circuit capacitance close to that of the a/d converter itself (25 pf). to measure longer time intervals, an external capacitor may be connected to an a/d channel and that channel selected whenever making a time measurement. figure 18-3: typical connections and internal configuration for time measurement pic18f66k80 a/d converter ctmu cted1 cted2 an x a/d voltage edg1 edg2 c ad c ext current source
? 2011 microchip technology inc. ds39977d-page 253 pic18f66k80 family 18.7 measuring temperature with the ctmu the constant current source provided by the ctmu module can be used for low-cost temperature measurement by exploiting a basic property of com- mon and inexpensive diodes. an on-chip temperature sense diode is provided on adc channel 29 to further simplify design and cost. 18.7.1 basic principal we can show that the forward voltage ( v f ) of a p-n junction, such as a diode, is an extension of the equation for the junction?s thermal voltage: where k is the boltzmann constant (1.38 x 10 -23 j k -1 ), t is the absolute junction temperature in kelvin, q is the electron charge (1.6 x 10 -19 c), i f is the forward current applied to the diode and i s is the diode?s characteristic saturation current, which varies between devices. since k and q are physical constants, and i s is a constant for the device, this only leaves t and i f as independent variables. if i f is held constant, it follows from the equa- tion that v f will vary as a function of t . as the natural log term of the equation will always be negative, the temper- ature will be negatively proportional to v f . in other words, as temperature increases, v f decreases. by using the ctmu?s current source to provide a constant i f , it becomes possible to calculate the temperature by measuring the v f across the diode. 18.7.2 implementation to implement this theory, all that is needed is to con- nect a regular junction diode to one of the microcon- troller?s a/d pins ( figure 18-2 ). the a/d channel multiplexer is shared by the ctmu and the adc. to perform a measurement, the multiplexer is config- ured to select the pin connected to the diode. the ctmu current source is then turned on and an a/d conversion is performed on the channel. as shown in the equivalent circuit diagram, the diode is driven by the ctmu at i f . the resulting v f across the diode is measured by the adc. a code snippet is shown in example 18-5 . figure 18-4: ctmu temperature measurement circuit example 18-5: routine for temperature measurement using internal diode v f = kt q 1n 1 ? i f i s ) ( pic ? microcontroller a/d converter ctmu current source mux a/d v f v f i f ctmu adc equivalent circuit simplified block diagram // initialize ctmu ctmuicon = 0x03; ctmuconhbits.ctmuen = 1; ctmuconlbits.edg1stat = 1; // initialize adc adcon0 = 0xe5; // enable adc and connect to internal diode adcon1 = 0x00; adcon2 = 0xbe; //right justified adcon0bits.go = 1; // start conversion while(adcon0bits.g0); temp = adres; // read adc results (inversely proportional to temperature) note: the temperature diode is not calibrated or standardized; the user must calibrate the diode to their application.
pic18f66k80 family ds39977d-page 254 ? 2011 microchip technology inc. 18.8 creating a delay with the ctmu module a unique feature on board the ctmu module is its ability to generate system clock independent output pulses based on either an external voltage or an external capacitor value. when using an external voltage, this is accomplished using the ctdin input pin as a trigger for the pulse delay. when using an external capacitor value, this is accomplished using the internal compara- tor voltage reference module and comparator 2 input pin.the pulse is output onto the ctpls pin. to enable this mode, set the tgen bit. see figure 18-5 for an example circuit. when ctmuds (padcfg1<0>) is cleared, the pulse delay is determined by the output of comparator 2, and when it is set, the pulse delay is determined by the input of ctdin. c delay is chosen by the user to determine the output pulse width on ctpls. the pulse width is calcu- lated by t = (c delay /i)*v , where i is known from the current source measurement step ( section 18.4.1 ?current source calibration? ) and v is the internal reference voltage (cv ref ). an example use of the external capacitor feature is interfacing with variable capacitive-based sensors, such as a humidity sensor. as the humidity varies, the pulse-width output on ctpls will vary. an example use of the ctdin feature is interfacing with a digital sensor. the ctpls output pin can be connected to an input capture pin and the varying pulse width measured to determine the sensor?s output in the application. to use this feature: 1. if ctmuds is cleared, initialize comparator 2. 2. if ctmuds is cleared, initialize the comparator voltage reference. 3. initialize the ctmu and enable time delay generation by setting the tgen bit. 4. set edg1stat. when ctmuds is cleared, as soon as c delay charges to the value of the voltage reference trip point, an output pulse is generated on ctpls. when ctmuds is set, as soon as ctdin is set, an output pulse is generated on ctpls. figure 18-5: typical connections and internal configuration for pulse delay generation c2 cv ref ctpls current source comparator ctmu cted1 ctmui c delay edg1 pic18f66k80 ctmuds c1 external reference external comparator ctdin
? 2011 microchip technology inc. ds39977d-page 255 pic18f66k80 family 18.9 measuring temperature with the ctmu module the ctmu, along with an internal diode, can be used to measure the temperature. the adc can be con- nected to the internal diode and the ctmu module can source the current to the diode. the adc reading will reflect the temperature. with the increase, the adc readings will go low. this can be used for low-cost temperature measurement applications. example 18-6: routine for temperature measurement using internal diode // initialize ctmu ctmuicon = 0x03; ctmuconhbits.ctmuen = 1; ctmuconlbits.edg1stat = 1; // initialize adc adcon0 = 0xe5; // enable adc and connect to internal diode adcon1 = 0x00; adcon2 = 0xbe; //right justified adcon0bits.go = 1; // start conversion while(adcon0bits.g0); temp = adres; // read adc results (inversely proportional to temperature) note: the temperature diode is not calibrated or standardized; the user must calibrate the diode to their application.
pic18f66k80 family ds39977d-page 256 ? 2011 microchip technology inc. 18.10 operation during sleep/idle modes 18.10.1 sleep mode when the device enters any sleep mode, the ctmu module current source is always disabled. if the ctmu is performing an operation that depends on the current source when sleep mode is invoked, the operation may not terminate correctly. capacitance and time measurements may return erroneous values. 18.10.2 idle mode the behavior of the ctmu in idle mode is determined by the ctmusidl bit (ctmuconh<5>). if ctmusidl is cleared, the module will continue to operate in idle mode. if ctmusidl is set, the module?s current source is disabled when the device enters idle mode. in this case, if the module is performing an operation when idle mode is invoked, the results will be similar to those with sleep mode. 18.11 effects of a reset on ctmu upon reset, all registers of the ctmu are cleared. this disables the ctmu module, turns off its current source and returns all configuration options to their default set- tings. the module needs to be re-initialized following any reset. if the ctmu is in the process of taking a measurement at the time of reset, the measurement will be lost. a partial charge may exist on the circuit that was being measured, which should be properly discharged before the ctmu makes subsequent attempts to make a measurement. the circuit is discharged by setting and clearing the idissen bit (ctmuconh<1>) while the a/d converter is connected to the appropriate channel. table 18-1: registers associated with ctmu module name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 ctmuconh ctmuen ? ctmusidl tgen edgen edgseqen idissen cttrig ctmuconl edg2pol edg2sel1 edg2sel0 edg1pol edg1sel1 edg1sel0 edg2stat edg1stat ctmuicon itrim5 itrim4 itrim3 it rim2 itrim1 itrim0 irng1 irng0 pir3 ? ? rc2if tx2if ctmuif ccp2if ccp1if ? pie3 ? ? rc2ie tx2ie ctmuie ccp2ie ccp1ie ? ipr3 ? ? rc2ip tx2ip ctmuip ccp2ip ccp1ip ? padcfg1 rdpu repu rfpu rgpu ? ? ? ctmuds legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used during eccp operation.
? 2011 microchip technology inc. ds39977d-page 257 pic18f66k80 family 19.0 capture/compare/pwm (ccp) modules pic18f66k80 family devices have four ccp (capture/compare/pwm) modules, designated ccp2 through ccp5. all the modules implement standard capture, compare and pulse-width modulation (pwm) modes. each ccp module contains a 16-bit register that can operate as a 16-bit capture register, a 16-bit compare register or a pwm master/slave duty cycle register. for the sake of clarity, all ccp module operation in the following sections is described with respect to ccp2, but is equally applicable to ccp3 through ccp5. note: throughout this section, generic references are used for register and bit names that are the same, except for an ?x? variable that indicates the item?s association with the specific ccp module. for example, the control register is named ccpxcon and refers to ccp2con through ccp5con. register 19-1: ccpxcon: ccpx contro l register (ccp2-ccp5 modules) ( 1 ) u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? dcxb1 dcxb0 ccpxm3 (1) ccpxm2 (1) ccpxm1 (1) ccpxm0 (1) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-4 dcxb<1:0>: pwm duty cycle bit 1 and bit 0 for ccpx module bits capture mode : unused. compare mode : unused. pwm mode : these bits are the two least significant bits (bit 1 and bit 0) of the 10-bit pwm duty cycle. the eight most significant bits (dcx<9:2>) of the duty cycle are found in ccprxl. bit 3-0 ccpxm<3:0> : ccpx module mode select bits (1) 0000 = capture/compare/pwm disabled (resets ccpx module) 0001 = reserved 0010 = compare mode: toggle output on match (ccpxif bit is set) 0011 = reserved 0100 = capture mode: every falling edge or can message received (time-stamp) (2) 0101 = capture mode: every rising edge or can message received (time-stamp) (2) 0110 = capture mode: every 4th rising edge or on every fourth can message received (time-stamp) (2 0111 = capture mode: every 16th rising edge or on every 16th can message received (time-stamp) (2) 1000 = compare mode: initialize ccpx pin low; on compare match, force ccpx pin high (ccpxif bit is set) 1001 = compare mode: initialize ccpx pin high; on compare match, force ccpx pin low (ccpxif bit is set) 1010 = compare mode: generate software interrupt on compare match (ccpxif bit is set, ccpx pin reflects i/o state) 1011 = compare mode: special event trigger; reset timer on ccpx match (ccpxif bit is set) 11xx =pwm mode note 1: ccpxm<3:0> = 1011 will only reset the timer and not start an a/d conversion on ccpx match. 2: available only on ccp2. selected by the cancap (ciocon<4>) bit. overrides the ccp2 input pin source.
pic18f66k80 family ds39977d-page 258 ? 2011 microchip technology inc. register 19-2: ccptmrs: ccp timer select register u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? c5tsel c4tsel c3tsel c2tsel c1tsel bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4 c5tsel: ccp5 timer selection bit 0 = ccp5 is based off of tmr1/tmr2 1 = ccp5 is based off of tmr3/tmr4 bit 3 c4tsel: ccp4 timer selection bit 0 = ccp4 is based off of tmr1/tmr2 1 = ccp4 is based off of tmr3/tmr4 bit 2 c3tsel: ccp3 timer selection bit 0 = ccp3 is based off of tmr1/tmr2 1 = ccp3 is based off of tmr3/tmr4 bit 1 c2tsel: ccp2 timer selection bit 0 = ccp2 is based off of tmr1/tmr2 1 = ccp2 is based off of tmr3/tmr4 bit 0 c1tsel: ccp1 timer selection bit 0 = eccp1 is based off of tmr1/tmr2 1 = eccp1 is based off of tmr3/tmr4
? 2011 microchip technology inc. ds39977d-page 259 pic18f66k80 family register 19-3: ccprxl: ccpx period low byte register r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ccprxl7 ccprxl6 ccprxl5 ccprxl4 ccprxl3 ccprxl2 ccprxl1 ccprxl0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 ccprxl<7:0>: ccpx period register low byte bits capture mode: capture register low byte compare mode: compare register low byte pwm mode: duty cycle register register 19-4: ccprxh: ccpx period high byte register r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ccprxh7 ccprxh6 ccprxh5 ccprxh4 ccprxh3 ccprxh2 ccprxh1 ccprxh0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 ccprxh<7:0>: ccpx period register high byte bits capture mode: capture register high byte compare mode: compare register high byte pwm mode: duty cycle buffer register
pic18f66k80 family ds39977d-page 260 ? 2011 microchip technology inc. 19.1 ccp module configuration each capture/compare/pwm module is associated with a control register (generically, ccpxcon) and a data register (ccprx). the data register, in turn, is comprised of two 8-bit registers: ccprxl (low byte) and ccprxh (high byte). all registers are both readable and writable. 19.1.1 ccp modules and timer resources the ccp modules utilize timers, 1 through 4, varying with the selected mode. various timers are available to the ccp modules in capture, compare or pwm modes, as shown in table 19-1 . table 19-1: ccp mode ? timer resource the assignment of a particular timer to a module is determined by the timer to ccp enable bits in the ccptmrs register (see register 19-2 ). all of the modules may be active at once and may share the same timer resource if they are configured to operate in the same mode (capture/compare or pwm) at the same time. the ccptmrs register selects the timers for ccp modules, 2, 3, 4 and 5. the possible configurations are shown in tab l e 1 9- 2 . table 19-2: timer assignments for ccp modules 2, 3, 4 and 5 19.1.2 open-drain output option when operating in output mode (the compare or pwm modes), the drivers for the ccpx pins can be optionally configured as open-drain outputs. this feature allows the voltage level on the pin to be pulled to a higher level through an external pull-up resistor and allows the output to communicate with external circuits without the need for additional level shifters. the open-drain output option is controlled by the ccpxod bits (odcon<6:2>). setting the appropriate bit configures the pin for the corresponding module for open-drain operation. ccp mode timer resource capture timer1 or timer3 compare pwm timer2 or timer4 ccptmrs register ccp2 ccp3 ccp4 ccp5 c2tsel capture/ compare mode pwm mode c3tsel capture/ compare mode pwm mode c4tsel capture/ compare mode pwm mode c5tsel capture/ compare mode pwm mode 0 tmr1 tmr2 0 tmr1 tmr2 0 tmr1 tmr2 00 tmr1 tmr2 1 tmr3 tmr4 1 tmr3 tmr4 1 tmr3 tmr4 01 tmr3 tmr4
? 2011 microchip technology inc. ds39977d-page 261 pic18f66k80 family 19.2 capture mode in capture mode, the ccprxh:ccprxl register pair captures the 16-bit value of the timer register selected in the ccptmrs when an event occurs on the ccpx pin. an event is defined as one of the following: ? every falling edge ? every rising edge ? every 4th rising edge ? every 16th rising edge the event is selected by the mode select bits, ccpxm<3:0> (ccpxcon<3:0>). when a capture is made, the interrupt request flag bit, ccpxif (pir4), is set; it must be cleared in software. if another capture occurs before the value in ccprx is read, the old captured value is overwritten by the new captured value. figure 19-1 shows the capture mode block diagram. 19.2.1 ccp pin configuration in capture mode, the appropriate ccpx pin should be configured as an input by setting the corresponding tris direction bit. 19.2.2 timer1/3 mode selection for the available timers (1/3) to be used for the capture feature, the used timers must be running in timer mode or synchronized counter mode. in asynchronous counter mode, the capture operation may not work. the timer to be used with each ccp module is selected in the ccptmrs register. (see section 19.1.1 ?ccp modules and timer resources? .) details of the timer assignments for the ccp modules are given in table 19-2 . figure 19-1: capture mode operation block diagram note: for ccp2 only, the capture mode can use the ccp2 input pin as the capture trigger for ccp2 or the input can function as a time-stamp through the can module. the can module provides the necessary control and trigger signals. ccpr3h ccpr3l tmr1h tmr1l set ccp3if tmr3 enable q1:q4 ccp3con<3:0> ccp3 pin prescaler ? 1, 4, 16 and edge detect tmr1 enable c3tsel c3tsel ccpr4h ccpr4l tmr1h tmr1l set ccp4if tmr3 enable ccp4con<3:0> ccp4 pin prescaler ? 1, 4, 16 tmr3h tmr3l tmr1 enable tmr3h tmr3l and edge detect 4 4 4 note: this block diagram uses ccp3 and ccp4, and their appropr iate timers as an example. for details on all of the ccp modules and their timer assignments, see table 19-2 . c4tsel c4tsel
pic18f66k80 family ds39977d-page 262 ? 2011 microchip technology inc. 19.2.3 software interrupt when the capture mode is changed, a false capture interrupt may be generated. the user should keep the ccpxie bit (pie4) clear to avoid false interrupts and should clear the flag bit, ccpxif, following any such change in operating mode. 19.2.4 ccp prescaler there are four prescaler settings in capture mode. they are specified as part of the operating mode selected by the mode select bits (ccpxm<3:0>). whenever the ccp module is turned off, or the ccp module is not in capture mode, the prescaler counter is cleared. this means that any reset will clear the prescaler counter. switching from one capture prescaler to another may generate an interrupt. doing that also will not clear the prescaler counter ? meaning the first capture may be from a non-zero prescaler. example 19-1 shows the recommended method for switching between capture prescalers. this example also clears the prescaler counter and will not generate the ?false? interrupt. example 19-1: changing between capture prescalers 19.2.5 can message time-stamp (ccp2 only) for ccp2, only the can capture event occurs when a message is received in any of the receive buffers. when configured, the can module provides the trigger to the ccp2 module to cause a capture event. this feature is provided to ?time-stamp? the received can messages. this feature is enabled by setting the cancap bit of the can i/o control register (ciocon<4>). the mes- sage receive signal from the can module then takes the place of the events on rc2/ccp2. if this feature is selected, then four different capture options for ccp2m<3:0> are available: ? 0100 ? every time a can message is received ? 0101 ? every time a can message is received ? 0110 ? every 4th time a can message is received ? 0111 ? capture mode, every 16th time a can message is received clrf ccpxcon ; turn ccp module off movlw new_capt_ps ; load wreg with the ; new prescaler mode ; value and ccp on movwf ccpxcon ; load ccpxcon with ; this value
? 2011 microchip technology inc. ds39977d-page 263 pic18f66k80 family 19.3 compare mode in compare mode, the 16-bit ccprx register value is constantly compared against the timer register pair value selected in the ccptmr register. when a match occurs, the ccpx pin can be: ? driven high ?driven low ? toggled (high-to-low or low-to-high) ? unchanged (that is, reflecting the state of the i/o latch) the action on the pin is based on the value of the mode select bits (ccpxm<3:0>). at the same time, the interrupt flag bit, ccpxif, is set. figure 19-2 gives the compare mode block diagram 19.3.1 ccp pin configuration the user must configure the ccpx pin as an output by clearing the appropriate tris bit. 19.3.2 timer1/3 mode selection if the ccpx module is using the compare feature in conjunction with any of the timer1/3 timers, the timers must be running in timer mode or synchronized counter mode. in asynchronous counter mode, the compare operation may not work. 19.3.3 software interrupt mode when the generate software interrupt mode is chosen (ccpxm<3:0> = 1010 ), the ccpx pin is not affected. only a ccp interrupt is generated, if enabled, and the ccpxie bit is set. 19.3.4 special event trigger all ccp modules are equipped with a special event trigger. this is an internal hardware signal generated in compare mode to trigger actions by other modules. the special event trigger is enabled by selecting the compare special event trigger mode bits (ccpxm<3:0> = 1011 ). for either ccpx module, the special event trigger resets the timer register pair for whichever timer resource is currently assigned as the module?s time base. this allows the ccprx registers to serve as a programmable period register for either timer. note: clearing the ccpxcon register will force the corresponding ccpx compare output latch (depending on device configuration) to the default low level. this is not the portx data latch. note: details of the timer assignments for the ccpx modules are given in ta b l e 1 9 - 2 .
pic18f66k80 family ds39977d-page 264 ? 2011 microchip technology inc. figure 19-2: compare mode operation block diagram ccpr5h ccpr5l tmr1h tmr1l comparator q s r output logic special event trigger set ccp5if ccp5 pin tris ccp5con<3:0> output enable tmr3h tmr3l 1 0 compare 4 (timer1/3 reset) match note: this block diagram uses ccp4 and ccp5, and their appr opriate timers as an example. for details on all of the ccp modules and their timer assignments, see table 19-2 . tmr1h tmr1l tmr3h tmr3l ccpr4h ccpr4l comparator c4tsel set ccp4if 1 0 q s r output logic special event trigger ccp4 pin tris ccp4con<3:0> output enable 4 (timer1/timer3 reset) compare match c5tsel
? 2011 microchip technology inc. ds39977d-page 265 pic18f66k80 family table 19-3: registers associated with capture, compare, timer1/3 name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif rcon ipen sboren cm ri to pd por bor pir3 ? ? rc2if tx2if ctmuif ccp2if ccp1if ? pie3 ? ? rc2ie tx2ie ctmuie ccp2ie ccp1ie ? ipr3 ? ? rc2ip tx2ip ctmuip ccp2ip ccp1ip ? pir4 tmr4if eeif cmp2if cmp1if ? ccp5if ccp4if ccp3if pie4 tmr4ie eeie cmp2ie cmp1ie ? ccp5ie ccp4ie ccp3ie ipr4 tmr4ip eeip cmp2ip cmp1ip ? ccp5ip ccp4ip ccp3ip trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 tmr1l timer1 register low byte tmr1h timer1 register high byte tmr3l timer3 register low byte tmr3h timer3 register high byte t1con tmr1cs1 tmr1cs0 t1ckps1 t1ckps0 soscen t1sync rd16 tmr1on t3con tmr3cs1 tmr3cs0 t3ckps1 t3ckps0 soscen t3sync rd16 tmr3on ccpr2l capture/compare/pwm register 2 low byte ccpr2h capture/compare/pwm register 2 high byte ccpr3l capture/compare/pwm register 3 low byte ccpr3h capture/compare/pwm register 3 high byte ccpr4l capture/compare/pwm register 4 low byte ccpr4h capture/compare/pwm register 4 high byte ccpr5l capture/compare/pwm register 5 low byte ccpr5h capture/compare/pwm register 5 high byte ccp2con ? ? dc2b1 dc2b0 ccp2m3 ccp2m2 ccp2m1 ccp2m0 ccp3con ? ? dc3b1 dc3b0 ccp3m3 ccp3m2 ccp3m1 ccp3m0 ccp4con ? ? dc4b1 dc4b0 ccp4m3 ccp4m2 ccp4m1 ccp4m0 ccp5con ? ? dc5b1 dc5b0 ccp5m3 ccp5m2 ccp5m1 ccp5m0 ccptmrs ? ? ? c5tsel c4tsel c3tsel c2tsel c1tsel pmd0 ccp5md ccp4md ccp3md ccp2md ccp1md uart2md uart1md sspmd legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by capture/compare or timer1/3.
pic18f66k80 family ds39977d-page 266 ? 2011 microchip technology inc. 19.4 pwm mode in pulse-width modulation (pwm) mode, the ccpx pin produces up to a 10-bit resolution pwm output. since the ccpx pin is multiplexed with a portc or portb data latch, the appropriate tris bit must be cleared to make the ccpx pin an output. figure 19-3 shows a simplified block diagram of the ccpx module in pwm mode. for a step-by-step procedure on how to set up the ccp module for pwm operation, see section 19.4.3 ?setup for pwm operation? . figure 19-3: simplified pwm block diagram a pwm output ( figure 19-4 ) has a time base (period) and a time that the output stays high (duty cycle). the frequency of the pwm is the inverse of the period (1/period). figure 19-4: pwm output 19.4.1 pwm period the pwm period is specified by writing to the pr2 register. the pwm period can be calculated using the following formula: equation 19-1: pwm frequency is defined as 1/[pwm period]. when tmr2 is equal to pr2, the following three events occur on the next increment cycle: ?tmr2 is cleared ? the ccp4 pin is set (an exception: if pwm duty cycle = 0%, the ccp4 pin will not be set) ? the pwm duty cycle is latched from ccpr4l into ccpr4h note: clearing the ccpxcon register will force the corresponding ccpx output latch (depending on device configuration) to the default low level. this is not the portx i/o data latch. ccpr4l ccpr4h (slave) comparator tmr2 comparator pr2 (note 1) r q s duty cycle registers ccp4con<5:4> clear timer, ccp1 pin and latch d.c. trisc<2> rc2/ccp1 note 1: the 8-bit tmr2 value is concatenated with the 2-bit internal q clock, or 2 bits of the prescaler, to create the 10-bit time base. 2: ccp4 and its appropriate timers are used as an example. for details on all of the ccp modules and their timer assignments, see table 19-2 . note: the timer2 postscalers (see section 15.0 ?timer2 module? ) are not used in the determination of the pwm frequency. the postscaler could be used to have a servo update rate at a different frequency than the pwm output. period duty cycle tmr2 = pr2 tmr2 = duty cycle tmr2 = pr2 pwm period = [(pr2) + 1] ? 4 ? t osc ? (tmr2 prescale value)
? 2011 microchip technology inc. ds39977d-page 267 pic18f66k80 family 19.4.2 pwm duty cycle the pwm duty cycle is specified, to use ccp4 as an example, by writing to the ccpr4l register and to the ccp4con<5:4> bits. up to 10-bit resolution is avail- able. the ccpr4l contains the eight msbs and the ccp4con<5:4> contains the two lsbs. this 10-bit value is represented by ccpr4l:ccp4con<5:4>. the following equation is used to calculate the pwm duty cycle in time: equation 19-2: ccpr4l and ccp4con<5:4> can be written to at any time, but the duty cycle value is not latched into ccpr4h until after a match between pr2 and tmr2 occurs (that is, the period is complete). in pwm mode, ccpr4h is a read-only register. the ccpr4h register and a two-bit internal latch are used to double-buffer the pwm duty cycle. this double-buffering is essential for glitchless pwm operation. when the ccpr4h and two-bit latch match tmr2, concatenated with an internal two-bit q clock or two bits of the tmr2 prescaler, the ccp4 pin is cleared. the maximum pwm resolution (bits) for a given pwm frequency is given by the equation: equation 19-3: table 19-4: example pwm frequencies and resolutions at 40 mhz 19.4.3 setup for pwm operation to configure the ccp module for pwm operation, using ccp4 as an example: 1. set the pwm period by writing to the pr2 register. 2. set the pwm duty cycle by writing to the ccpr4l register and ccp4con<5:4> bits. 3. make the ccp4 pin an output by clearing the appropriate tris bit. 4. set the tmr2 prescale value, then enable timer2 by writing to t2con. 5. configure the ccp4 module for pwm operation. pwm duty cycle = (ccpr4l:ccp4con<5:4>) ? t osc ? (tmr2 prescale value) note: if the pwm duty cycle value is longer than the pwm period, the ccp4 pin will not be cleared. f osc f pwm --------------- ?? ?? log 2 ?? log ----------------------------- b i t s = pwm resolution (max) pwm frequency 2.44 khz 9.77 khz 39.06 khz 156.25 khz 312.50 khz 416.67 khz timer prescaler (1, 4, 16)1641111 pr2 value ffh ffh ffh 3fh 1fh 17h maximum resolution (bits) 10 10 10 8 7 6.58
pic18f66k80 family ds39977d-page 268 ? 2011 microchip technology inc. table 19-5: registers associated with pwm and timers name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif rcon ipen sboren cm ri to pd por bor pir3 ? ? rc2if tx2if ctmuif ccp2if ccp1if ? pie3 ? ? rc2ie tx2ie ctmuie ccp2ie ccp1ie ? ipr3 ? ? rc2ip tx2ip ctmuip ccp2ip ccp1ip ? pir4 tmr4if eeif cmp2if cmp1if ? ccp5if ccp4if ccp3if pie4 tmr4ie eeie cmp2ie cmp1ie ? ccp5ie ccp4ie ccp3ie ipr4 tmr4ip eeip cmp2ip cmp1ip ? ccp5ip ccp4ip ccp3ip trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 tmr2 timer2 register tmr4 timer4 register pr2 timer2 period register pr4 timer4 period register t2con ? t2outps3 t2outps2 t2outps1 t2outps0 tmr2on t2ckps1 t2ckps0 t4con ? t4outps3 t4outps2 t4outps1 t4outps0 tmr4on t4ckps1 t4ckps0 ccpr2l capture/compare/pwm register 2 low byte ccpr2h capture/compare/pwm register 2 high byte ccpr3l capture/compare/pwm register 3 low byte ccpr3h capture/compare/pwm register 3 high byte ccpr4l capture/compare/pwm register 4 low byte ccpr4h capture/compare/pwm register 4 high byte ccpr5l capture/compare/pwm register 5 low byte ccpr5h capture/compare/pwm register 5 high byte ccp2con ? ? dc2b1 dc2b0 ccp2m3 ccp2m2 ccp2m1 ccp2m0 ccp3con ? ? dc3b1 dc3b0 ccp3m3 ccp3m2 ccp3m1 ccp3m0 ccp4con ? ? dc4b1 dc4b0 ccp4m3 ccp4m2 ccp4m1 ccp4m0 ccp5con ? ? dc5b1 dc5b0 ccp5m3 ccp5m2 ccp5m1 ccp5m0 ccptmrs ? ? ? c5tsel c4tsel c3tsel c2tsel c1tsel pmd0 ccp5md ccp4md ccp3md ccp2md ccp1md uart2md uart1md sspmd legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by pwm or timer2/4.
? 2011 microchip technology inc. ds39977d-page 269 pic18f66k80 family 20.0 enhanced capture/compare/pwm (eccp) module pic18f66k80 family devices have one enhanced capture/compare/pwm (eccp) module: eccp1. these modules contain a 16-bit register, which can operate as a 16-bit capture register, a 16-bit compare register or a pwm master/s lave duty cycle register. these eccp modules are upward compatible with ccp eccp1 is implemented as standard ccp modules with enhanced pwm capabilities. these include: ? provision for two or four output channels ? output steering modes ? programmable polarity ? programmable dead-band control ? automatic shutdown and restart the enhanced features are discussed in detail in section 20.4 ?pwm (enhanced mode)? . the eccp1 module uses the control register, ccp1con. the control registers, ccp2con through ccp5con, are for the modules, ccp2 through ccp5.
pic18f66k80 family ds39977d-page 270 ? 2011 microchip technology inc. register 20-1: ccp1con: enhanced capture/compare/pwm1 control r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 p1m1 p1m0 dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 p1m<1:0>: enhanced pwm output configuration bits if ccp1m<3:2> = 00 , 01 , 10 : xx = p1a assigned as capture/compare input/output; p1b, p1c and p1d assigned as port pins if ccp1m<3:2> = 11 : 00 = single output: p1a, p1b, p1c and p1d controlled by steering (see section 20.4.7 ?pulse steering mode? ) 01 = full-bridge output forward: p1d modulated; p1a active; p1b, p1c inactive 10 = half-bridge output: p1a, p1b modulated with dead-band control; p1c and p1d assigned as port pins 11 = full-bridge output reverse: p1b modulated; p1c active; p1a and p1d inactive bit 5-4 dc1b<1:0> : pwm duty cycle bit 1 and bit 0 capture mode: unused. compare mode: unused. pwm mode: these bits are the two lsbs of the 10-bit pwm duty cycle. the eight msbs of the duty cycle are found in ccpr1l. bit 3-0 ccp1m<3:0> : eccp1 mode select bits 0000 = capture/compare/pwm off (resets eccp1 module) 0001 = reserved 0010 = compare mode, toggle output on match 0011 = capture mode 0100 = capture mode, every falling edge 0101 = capture mode, every rising edge 0110 = capture mode, every fourth rising edge 0111 = capture mode, every 16 th rising edge 1000 = compare mode, initialize eccp1 pin low, set output on compare match (set ccp1if) 1001 = compare mode, initialize eccp1 pin high, clear output on compare match (set ccp1if) 1010 = compare mode, generate software interrupt only, eccp1 pin reverts to i/o state 1011 = compare mode, trigger special event (eccp1 resets tmr1 or tmr3, starts a/d conversion, sets ccp1if bit) 1100 = pwm mode; p1a and p1c active-high; p1b and p1d active-high 1101 = pwm mode; p1a and p1c active-high; p1b and p1d active-low 1110 = pwm mode; p1a and p1c active-low; p1b and p1d active-high 1111 = pwm mode; p1a and p1c active-low; p1b and p1d active-low
? 2011 microchip technology inc. ds39977d-page 271 pic18f66k80 family in addition to the expanded range of modes available through the ccp1con and eccp1as registers, the eccp module has two additional registers associated with enhanced pwm operation and auto-shutdown features. they are: ? eccp1del ? enhanced pwm control ? pstr1con ? pulse steering control register 20-2: ccptmrs: ccp timer select register u-0 u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x ? ? ? c5tsel c4tsel c3tsel c2tsel c1tsel bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4 c5tsel: ccp5 timer selection bit 0 = ccp5 is based off of tmr1/tmr2 1 = ccp5 is based off of tmr3/tmr4 bit 3 c4tsel: ccp4 timer selection bit 0 = ccp4 is based off of tmr1/tmr2 1 = ccp4 is based off of tmr3/tmr4 bit 2 c3tsel: ccp3 timer selection bit 0 = ccp3 is based off of tmr1/tmr2 1 = ccp3 is based off of tmr3/tmr4 bit 1 c2tsel: ccp2 timer selection bit 0 = ccp2 is based off of tmr1/tmr2 1 = ccp2 is based off of tmr3/tmr4 bit 0 c1tsel: ccp1 timer selection bit 0 = eccp1 is based off of tmr1/tmr2 1 = eccp1 is based off of tmr3/tmr4
pic18f66k80 family ds39977d-page 272 ? 2011 microchip technology inc. 20.1 eccp outputs and configuration the enhanced ccp module may have up to four pwm outputs, depending on the selected operating mode. the ccp1con register is modified to allow control over four pwm outputs: eccp1/p1a, p1b, p1c and p1d. applications can use one, two or four of these outputs. the outputs that are active depend on the eccp operating mode selected. the pin assignments are summarized in table 20-2 . to configure the i/o pins as pwm outputs, the proper pwm mode must be selected by setting the p1m<1:0> and ccp1m<3:0> bits. the appropriate tris direction bits for the port pins must also be set as outputs. 20.1.1 eccp module and timer resources the eccp modules use timers, 1, 2, 3 and 4, depend- ing on the mode selected. these timers are available to ccp modules in capture, compare or pwm modes, as shown in table 20-1 . table 20-1: eccp mode ? timer resource the assignment of a particular timer to a module is determined by the timer to eccp enable bits in the ccptmrs register ( register 20-2 ). the interactions between the two modules are depicted in figure 20-1 . capture operations are designed to be used when the timer is configured for synchronous counter mode. capture operations may not work as expected if the associated timer is configured for asynchronous counter mode. 20.2 capture mode in capture mode, the ccpr1h:ccpr1l register pair captures the 16-bit value of the tmr1 or tmr3 registers when an event occurs on the corresponding eccp1 pin. an event is defined as one of the following: ? every falling edge ? every rising edge ? every fourth rising edge ?every 16 th rising edge the event is selected by the mode select bits, ccp1m<3:0> (ccp1con<3:0>). when a capture is made, the interrupt request flag bit, ccp1if, is set (pir3<1>). the flag must be cleared by software. if another capture occurs before the value in the ccpr1h/l register is read, the old captured value is overwritten by the new captured value. 20.2.1 eccp pin configuration in capture mode, the appropriate eccp1 pin should be configured as an input by setting the corresponding tris direction bit. eccp mode timer resource capture timer1 or timer3 compare timer1 or timer3 pwm timer2 or timer4 note: if the eccp1 pin is configured as an out- put, a write to the port can cause a capture condition.
? 2011 microchip technology inc. ds39977d-page 273 pic18f66k80 family 20.2.2 timer1/2/3/4 mode selection the timers that are to be used with the capture feature (timer1 2, 3 or 4) must be running in timer mode or synchronized counter mode. in asynchronous counter mode, the capture operation may not work. the timer to be used with each eccp module is selected in the ccptmrs register ( register 20-2 ). 20.2.3 software interrupt when the capture mode is changed, a false capture interrupt may be generated. the user should keep the ccp1ie interrupt enable bit clear to avoid false inter- rupts. the interrupt flag bit, ccp1if, should also be cleared following any such change in operating mode. 20.2.4 eccp prescaler there are four prescaler settings in capture mode; they are specified as part of the operating mode selected by the mode select bits (ccp1m<3:0>). whenever the eccp module is turned off, or capture mode is dis- abled, the prescaler counter is cleared. this means that any reset will clear the prescaler counter. switching from one capture prescaler to another may generate an interrupt. also, the prescaler counter will not be cleared; therefore, the first capture may be from a non-zero prescaler. example 20-1 provides the recommended method for switching between capture prescalers. this example also clears the prescaler counter and will not generate the ?false? interrupt. example 20-1: changing between capture prescalers figure 20-1: capture mode operation block diagram clrf ccp1con ; turn eccp module off movlw new_capt_ps ; load wreg with the ; new prescaler mode ; value and eccp on movwf ccp1con ; load eccp1con with ; this value ccpr1h ccpr1l tmr1h tmr1l set ccp1if tmr3 enable q1:q4 ccp1con<3:0> eccp1 pin prescaler ? 1, 4, 16 and edge detect tmr1 enable c1tsel0 tmr3h tmr3l 4 4 c1tsel1 c1tsel2 c1tsel0 c1tsel1 c1tsel2
pic18f66k80 family ds39977d-page 274 ? 2011 microchip technology inc. 20.3 compare mode in compare mode, the 16-bit ccpr1 register value is constantly compared against the timer register pair value selected in the ccptmr1 register. when a match occurs, the eccp1 pin can be: ? driven high ?driven low ? toggled (high-to-low or low-to-high) ? unchanged (that is, reflecting the state of the i/o latch) the action on the pin is based on the value of the mode select bits (ccp1m<3:0>). at the same time, the interrupt flag bit, ccp1if, is set. 20.3.1 eccp pin configuration users must configure the eccp1 pin as an output by clearing the appropriate tris bit. 20.3.2 timer1/2/3/4 mode selection timer1, 2, 3 or 4 must be running in timer mode or synchronized counter mode if the eccp module is using the compare feature. in asynchronous counter mode, the compare operation will not work reliably. 20.3.3 software interrupt mode when the generate software interrupt mode is chosen (ccp1m<3:0> = 1010 ), the eccp1 pin is not affected; only the ccp1if interrupt flag is affected. 20.3.4 special event trigger the eccp module is equipped with a special event trigger. this is an internal hardware signal generated in compare mode to trigger actions by other modules. the special event trigger is enabled by selecting the compare special event trigger mode (ccp1m<3:0> = 1011 ). the special event trigger resets the timer register pair for whichever timer resource is currently assigned as the module?s time base. this allows the ccpr1 registers to serve as a programmable period register for either timer. the special event trigger can also start an a/d conver- sion. in order to do this, the a/d converter must already be enabled. figure 20-2: compare mode operation block diagram note: clearing the ccp1con register will force the eccp1 compare output latch (depending on device configuration) to the default low level. this is not the port i/o data latch. tmr1h tmr1l tmr3h tmr3l ccpr1h ccpr1l comparator set ccp1if 1 0 q s r output logic eccp1 pin tris ccp1con<3:0> output enable 4 (timer1/timer3 reset, a/d trigger) compare match c1tsel0 c1tsel1 c1tsel2 special event trigger
? 2011 microchip technology inc. ds39977d-page 275 pic18f66k80 family 20.4 pwm (enhanced mode) the enhanced pwm mode can generate a pwm signal on up to four different output pins with up to 10 bits of resolution. it can do this through four different pwm output modes: ? single pwm ? half-bridge pwm ? full-bridge pwm, forward mode ? full-bridge pwm, reverse mode to select an enhanced pwm mode, the p1m bits of the ccp1con register must be set appropriately. the pwm outputs are multiplexed with i/o pins and are designated: p1a, p1b, p1c and p1d. the polarity of the pwm pins is configurable and is selected by setting the ccp1m bits in the ccp1con register appropriately. table 20-1 provides the pin assignments for each enhanced pwm mode. figure 20-3 provides an example of a simplified block diagram of the enhanced pwm module. figure 20-3: example simplified block diagram of the enhanced pwm mode note: to prevent the generation of an incomplete waveform when the pwm is first enabled, the eccp module waits until the start of a new pwm period before generating a pwm signal. note 1: the tris register value for each pwm output must be configured appropriately. 2: any pin not used by an enhanced pwm mode is available for alternate pin functions. ccpr1l ccpr1h (slave) comparator tmr2 comparator pr2 (1) rq s duty cycle registers dc1b<1:0> clear timer2, toggle pwm pin and latch duty cycle note 1: the 8-bit tmr2 register is concatenated with the 2-bit inte rnal q clock, or 2 bits of the prescaler, to create the 10-bit time base. tris eccp1/output pi n tris output pi n tris output pi n tris output pi n output controller p1m<1:0> 2 ccp1m<3:0> 4 eccp1del eccp1/p1a p1b p1c p1d
pic18f66k80 family ds39977d-page 276 ? 2011 microchip technology inc. table 20-2: example pin assignments for various pwm enhanced modes figure 20-4: example pwm (enhanced mode) output relationships (active-high state) eccp mode p1m<1:0> p1a p1b p1c p1d single 00 yes (1) yes (1) yes (1) yes (1) half-bridge 10 yes yes no no full-bridge, forward 01 yes yes yes yes full-bridge, reverse 11 yes yes yes yes note 1: outputs are enabled by pulse steering in single mode (see register 20-5 ). 0 period 00 10 01 11 signal pr2 + 1 p1m<1:0> p1a modulated p1a modulated p1b modulated p1a active p1b inactive p1c inactive p1d modulated p1a inactive p1b modulated p1c active p1d inactive pulse width (single output) (half-bridge) (full-bridge, forward) (full-bridge, reverse) delay (1) delay (1) relationships: ? period = 4 * t osc * (pr2 + 1) * (tmr2 prescale value) ? pulse width = t osc * (ccpr1l<7:0>:ccp1con<5:4>) * (tmr2 prescale value) ? delay = 4 * t osc * (eccp1del<6:0>) note 1: dead-band delay is programmed using the eccp1del register ( section 20.4.6 ?programmable dead-band delay mode? ).
? 2011 microchip technology inc. ds39977d-page 277 pic18f66k80 family figure 20-5: example enhanced pwm output relationships (active-low state) 0 period 00 10 01 11 signal pr2 + 1 p1m<1:0> p1a modulated p1a modulated p1b modulated p1a active p1b inactive p1c inactive p1d modulated p1a inactive p1b modulated p1c active p1d inactive pulse width (single output) (half-bridge) (full-bridge, forward) (full-bridge, reverse) delay (1) delay (1) relationships: ? period = 4 * t osc * (pr2 + 1) * (tmr2 prescale value) ? pulse width = t osc * (ccpr1l<7:0>:ccp1con<5:4>) * (tmr2 prescale value) ? delay = 4 * t osc * (eccp1del<6:0>) note 1: dead-band delay is programmed using the eccp1del register ( section 20.4.6 ?programmable dead-band delay mode? ).
pic18f66k80 family ds39977d-page 278 ? 2011 microchip technology inc. 20.4.1 half-bridge mode in half-bridge mode, two pins are used as outputs to drive push-pull loads. the pwm output signal is output on the p1a pin, while the complementary pwm output signal is output on the p1b pin (see figure 20-6 ). this mode can be used for half-bridge applications, as shown in figure 20-7 , or for full-bridge applications, where four power switches are being modulated with two pwm signals. in half-bridge mode, the programmable dead-band delay can be used to prevent shoot-through current in half-bridge power devices. the value of the p1dc<6:0> bits of the eccp1del register sets the number of instruction cycles before the output is driven active. if the value is greater than the duty cycle, the corresponding output remains inactive during the entire cycle. for more details on the dead-band delay operations, see section 20.4.6 ?programmable dead-band delay mode? . since the p1a and p1b outputs are multiplexed with the port data latches, the associated tris bits must be cleared to configure p1a and p1b as outputs. figure 20-6: example of half-bridge pwm output figure 20-7: example of half-bridge applications period pulse width td td (1) p1a (2) p1b (2) td = dead-band delay period (1) (1) note 1: at this time, the tmr2 register is equal to the pr2 register. 2: output signals are shown as active-high. p1a p1b fet driver fet driver load + - + - fet driver fet driver v+ load fet driver fet driver p1a p1b standard half-bridge circuit (?push-pull?) half-bridge output driving a full-bridge circuit
? 2011 microchip technology inc. ds39977d-page 279 pic18f66k80 family 20.4.2 full-bridge mode in full-bridge mode, all four pins are used as outputs. an example of a full-bridge application is provided in figure 20-8 . in the forward mode, the p1a pin is driven to its active state and the p1d pin is modulated, while the p1b and p1c pins are driven to their inactive state, as provided in figure 20-9 . in the reverse mode, the p1c pin is driven to its active state and the p1b pin is modulated, while the p1a and p1d pins are driven to their inactive state, as provided figure 20-9 . the p1a, p1b, p1c and p1d outputs are multiplexed with the port data latches. the associated tris bits must be cleared to configure the p1a, p1b, p1c and p1d pins as outputs. figure 20-8: example of full-bridge application p1a p1c fet driver fet driver v+ v- load fet driver fet driver p1b p1d qa qb qd qc
pic18f66k80 family ds39977d-page 280 ? 2011 microchip technology inc. figure 20-9: example of full-bridge pwm output period pulse width p1a (2) p1b (2) p1c (2) p1d (2) forward mode (1) period pulse width p1a (2) p1c (2) p1d (2) p1b (2) reverse mode (1) (1) (1) note 1: at this time, the tmr2 register is equal to the pr2 register. 2: the output signal is shown as active-high.
? 2011 microchip technology inc. ds39977d-page 281 pic18f66k80 family 20.4.2.1 direction change in full-bridge mode in the full-bridge mode, the p1m1 bit in the ccp1con register allows users to control the forward/reverse direction. when the application firmware changes this direction control bit, the module will change to the new direction on the next pwm cycle. a direction change is initiated in software by changing the p1m1 bit of the ccp1con register. the following sequence occurs prior to the end of the current pwm period: ? the modulated outputs (p1b and p1d) are placed in their inactive state. ? the associated unmodulated outputs (p1a and p1c) are switched to drive in the opposite direction. ? pwm modulation resumes at the beginning of the next period. for an illustration of this sequence, see figure 20-10 . the full-bridge mode does not provide a dead-band delay. as one output is modulated at a time, a dead-band delay is generally not required. there is a situation where a dead-band delay is required. this situation occurs when both of the following conditions are true: ? the direction of the pwm output changes when the duty cycle of the output is at or near 100%. ? the turn-off time of the power switch, including the power device and driver circuit, is greater than the turn-on time. figure 20-11 shows an example of the pwm direction changing from forward to reverse, at a near 100% duty cycle. in this example, at time, t1, the p1a and p1d outputs become inactive, while the p1c output becomes active. since the turn-off time of the power devices is longer than the turn-on time, a shoot-through current will flow through power devices, qc and qd (see figure 20-8 ), for the duration of ?t?. the same phenomenon will occur to power devices, qa and qb, for pwm direction change from reverse to forward. if changing pwm direction at high duty cycle is required for an application, two possible solutions for eliminating the shoot-through current are: ? reduce pwm duty cycle for one pwm period before changing directions. ? use switch drivers that can drive the switches off faster than they can drive them on. other options to prevent shoot-through current may exist. figure 20-10: example of pwm direction change pulse width period (1) signal note 1: the direction bit, p1m1 of the ccp1con register, is written any time during the pwm cycle. 2: when changing directions, the p1a and p1c signals switch before the end of the current pwm cycle. the modulated p1b and p1d signals are inactive at this time. the length of this time is: (1/f osc ) ? tmr2 prescale value . period (2) p1a (active-high) p1b (active-high) p1c (active-high) p1d (active-high) pulse width
pic18f66k80 family ds39977d-page 282 ? 2011 microchip technology inc. figure 20-11: example of pwm direction change at near 100% duty cycle 20.4.3 start-up considerations when any pwm mode is used, the application hardware must use the proper external pull-up and/or pull-down resistors on the pwm output pins. the ccp1m<1:0> bits of the ccp1con register allow the user to choose whether the pwm output signals are active-high or active-low for each pair of pwm output pins (p1a/p1c and p1b/p1d). the pwm output polarities must be selected before the pwm pin output drivers are enabled. changing the polarity configura- tion while the pwm pin output drivers are enabled is not recommended since it may result in damage to the application circuits. the p1a, p1b, p1c and p1d output latches may not be in the proper states when the pwm module is initialized. enabling the pwm pin output drivers at the same time as the enhanced pwm modes may cause damage to the application circuit. the enhanced pwm modes must be enabled in the proper output mode and complete a full pwm cycle before enabling the pwm pin output drivers. the completion of a full pwm cycle is indicated by the tmr2if or tmr4if bit of the pir1 or pir4 register being set as the second pwm period begins. 20.4.4 enhanced pwm auto-shutdown mode the pwm mode supports an auto-shutdown mode that will disable the pwm outputs when an external shutdown event occurs. auto-shutdown mode places the pwm output pins into a predetermined state. this mode is used to help prevent the pwm from damaging the application. the auto-shutdown sources are selected using the eccp1as<2:0> bits (eccp1as<6:4>). a shutdown event may be generated by: ? a logic ? 0 ? on the pin that is assigned the flt0 input function ? comparator c1 ? comparator c2 ? setting the eccp1ase bit in firmware forward period reverse period p1a t on t off t = t off ? t on p1b p1c p1d external switch d potential shoot-through current note 1: all signals are shown as active-high. 2: t on is the turn-on delay of power switch, qc, and its driver. 3: t off is the turn-off delay of power switch, qd, and its driver. external switch c t1 pw pw note: when the microcontroller is released from reset, all of the i/o pins are in the high-impedance state. the external circuits must keep the power switch devices in the off state until the micro- controller drives the i/o pins with the proper signal levels or activates the pwm output(s).
? 2011 microchip technology inc. ds39977d-page 283 pic18f66k80 family a shutdown condition is indicated by the eccp1ase (auto-shutdown event status) bit (eccp1as<7>). if the bit is a ? 0 ?, the pwm pins are operating normally. if the bit is a ? 1 ?, the pwm outputs are in the shutdown state. when a shutdown event occurs, two things happen: ? the eccp1ase bit is set to ? 1 ?. the eccp1ase will remain set until cleared in firmware or an auto-restart occurs. (see section 20.4.5 ?auto-restart mode? .) ? the enabled pwm pins are asynchronously placed in their shutdown states. the pwm output pins are grouped into pairs (p1a/p1c) and (p1b/p1d). the state of each pin pair is determined by the pss1ac and pss1bd bits (eccp1as<3:2> and <1:0>, respectively). each pin pair may be placed into one of three states: ? drive logic ? 1 ? ? drive logic ? 0 ? ? tri-state (high-impedance) register 20-3: eccp1as: eccp1 auto-shutdown control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 eccp1ase eccp1as2 eccp1as1 eccp1as0 pss1ac1 pss1ac0 pss1bd1 pss1bd0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 eccp1ase: eccp auto-shutdown event status bit 1 = a shutdown event has occurred; eccp outputs are in a shutdown state 0 = eccp outputs are operating bit 6-4 eccp1as<2:0>: eccp auto-shutdown source select bits 000 = auto-shutdown is disabled 001 = comparator c1out output is high 010 = comparator c2out output is high 011 = either comparator c1out or c2out is high 100 =v il on flt0 pin 101 =v il on flt0 pin or comparator c1out output is high 110 =v il on flt0 pin or comparator c2out output is high 111 =v il on flt0 pin or comparator c1out or comparator c2out is high bit 3-2 pss1ac<1:0>: p1a and p1c pins shutdown state control bits 00 = drive pins, p1a and p1c, to ? 0 ? 01 = drive pins, p1a and p1c, to ? 1 ? 1x = pins, p1a and p1c, tri-state bit 1-0 pss1bd<1:0>: p1b and p1d pins shutdown state control bits 00 = drive pins, p1b and p1d, to ? 0 ? 01 = drive pins, p1b and p1d, to ? 1 ? 1x = pins, p1b and p1d, tri-state note 1: the auto-shutdown condition is a level-based signal, not an edge-based signal. as long as the level is present, the auto-shutdown will persist. 2: writing to the eccp1ase bit is disabled while an auto-shutdown condition persists. 3: once the auto-shutdown condition has been removed and the pwm restarted (either through firmware or auto-restart), the pwm signal will always restart at the beginning of the next pwm period.
pic18f66k80 family ds39977d-page 284 ? 2011 microchip technology inc. figure 20-12: pwm auto-shutdown with firmware restart (p1rsen = 0 ) 20.4.5 auto-restart mode the enhanced pwm can be configured to automatically restart the pwm signal once the auto-shutdown condi- tion has been removed. auto-restart is enabled by setting the p1rsen bit (eccp1del<7>). if auto-restart is enabled, the eccp1ase bit will remain set as long as the auto-shutdown condition is active. when the auto-shutdown condition is removed, the eccp1ase bit will be cleared via hardware and normal operation will resume. the module will wait until the next pwm period begins, however, before re-enabling the output pin. this behav- ior allows the auto-shutdown with auto-restart features to be used in applications based on current mode of pwm control. figure 20-13: pwm auto-shutdown with auto-restart enabled (p1rsen = 1 ) shutdown pwm eccp1ase bit activity event shutdown event occurs shutdown event clears pwm resumes normal pwm start of pwm period eccp1ase cleared by firmware pwm period shutdown pwm eccp1ase bit activity event shutdown event occurs shutdown event clears pwm resumes normal pwm start of pwm period pwm period
? 2011 microchip technology inc. ds39977d-page 285 pic18f66k80 family 20.4.6 programmable dead-band delay mode in half-bridge applications, where all power switches are modulated at the pwm frequency, the power switches normally require more time to turn off than to turn on. if both the upper and lower power switches are switched at the same time (one turned on and the other turned off), both switches may be on for a short period until one switch completely turns off. during this brief interval, a very high current (shoot-through current) will flow through both power switches, shorting the bridge supply. to avoid this potentially destructive shoot-through current from flowing during switching, turning on either of the power switches is normally delayed to allow the other switch to completely turn off. in half-bridge mode, a digitally programmable dead-band delay is available to avoid shoot-through current from destroying the bridge power switches. the delay occurs at the signal transition from the non-active state to the active state. for an illustration, see figure 20-14 . the lower seven bits of the associated eccp1del register ( register 20-4 ) set the delay period in terms of microcontroller instruction cycles (t cy or 4 t osc ). figure 20-14: example of half-bridge pwm output figure 20-15: example of half-bridge applications period pulse width td td (1) p1a (2) p1b (2) td = dead-band delay period (1) (1) note 1: at this time, the tmr2 register is equal to the pr2 register. 2: output signals are shown as active-high. p1a p1b fet driver fet driver v+ v- load + v - + v - standard half-bridge circuit (?push-pull?)
pic18f66k80 family ds39977d-page 286 ? 2011 microchip technology inc. 20.4.7 pulse steering mode in single output mode, pulse steering allows any of the pwm pins to be the modulated signal. additionally, the same pwm signal can simultaneously be available on multiple pins. once the single output mode is selected (ccp1m<3:2> = 11 and p1m<1:0> = 00 of the ccp1con register), the user firmware can bring out the same pwm signal to one, two, three or four output pins by setting the appropriate str bits (pstr1con<3:0>), as provided in table 20-2 . while the pwm steering mode is active, the ccp1m<1:0> bits (ccp1con<1:0>) select the pwm output polarity for the p1 pins. the pwm auto-shutdown operation also applies to the pwm steering mode, as described in section 20.4.4 ?enhanced pwm auto-shutdown mode? . an auto-shutdown event will only affect pins that have pwm outputs enabled. register 20-4: eccp1del: e nhanced pwm control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 p1rsen p1dc6 p1dc5 p1dc4 p1dc3 p1dc2 p1dc1 p1dc0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 p1rsen: pwm restart enable bit 1 = upon auto-shutdown, the eccp1ase bit clears automatically once the shutdown event goes away; the pwm restarts automatically 0 = upon auto-shutdown, eccp1ase must be cleared by software to restart the pwm bit 6-0 p1dc<6:0>: pwm delay count bits p1dcn = number of f osc /4 (4 * t osc ) cycles between the scheduled time when a pwm signal should transition active and the actual time it does transition active. note: the associated tris bits must be set to output (? 0 ?) to enable the pin output driver in order to see the pwm signal on the pin.
? 2011 microchip technology inc. ds39977d-page 287 pic18f66k80 family register 20-5: pstr1con: pulse steering control (1) r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-1 cmpl1 cmpl0 ? strsync strd strc strb stra bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 cmpl<1:0>: complementary mode output assignment steering sync bits 00 = see str. 01 = pa and pb are selected as the complementary output pair 10 = pa and pc are selected as the complementary output pair 11 = pa and pd are selected as the complementary output pair bit 5 unimplemented: read as ? 0 ? bit 4 strsync: steering sync bit 1 = output steering update occurs on the next pwm period 0 = output steering update occurs at the beginning of the instruction cycle boundary bit 3 strd: steering enable bit d 1 = p1d pin has the pwm waveform with polarity control from ccp1m<1:0> 0 = p1d pin is assigned to port pin bit 2 strc: steering enable bit c 1 = p1c pin has the pwm waveform with polarity control from ccp1m<1:0> 0 = p1c pin is assigned to port pin bit 1 strb: steering enable bit b 1 = p1b pin has the pwm waveform with polarity control from ccp1m<1:0> 0 = p1b pin is assigned to port pin bit 0 stra: steering enable bit a 1 = p1a pin has the pwm waveform with polarity control from ccp1m<1:0> 0 = p1a pin is assigned to port pin note 1: the pwm steering mode is available only when the ccp1con register bits, ccp1m<3:2> = 11 and p1m<1:0> = 00 .
pic18f66k80 family ds39977d-page 288 ? 2011 microchip technology inc. figure 20-16: simplified steering block diagram (1,2) 20.4.7.1 steering synchronization the strsync bit of the pstr1con register gives the user two choices for when the steering event will happen. when the strsync bit is ? 0 ?, the steering event will happen at the end of the instruction that writes to the pstr1con register. in this case, the out- put signal at the p1 pins may be an incomplete pwm waveform. this operation is useful when the user firmware needs to immediately remove a pwm signal from the pin. when the strsync bit is ? 1 ?, the effective steering update will happen at the beginning of the next pwm period. in this case, steering on/off the pwm output will always produce a complete pwm waveform. figures 20-17 and 20-18 illustrate the timing diagrams of the pwm steering depending on the strsync setting. figure 20-17: example of steering event at end of instruction (strsync = 0) figure 20-18: example of steering event at beginning of instruction (strsync = 1) 1 0 tris output pin port data p1a signal stra 1 0 tris output pin port data strb 1 0 tris output pin port data strc 1 0 tris output pin port data strd note 1: port outputs are configured as displayed when the ccp1con register bits, p1m<1:0> = 00 and ccp1m<3:2> = 11 . 2: single pwm output requires setting at least one of the str bits. ccp1m1 ccp1m0 ccp1m1 ccp1m0 pwm p1n = pwm str p1 port data pwm period port data pwm port data p1n = pwm str p1 port data
? 2011 microchip technology inc. ds39977d-page 289 pic18f66k80 family 20.4.8 operation in power-managed modes in sleep mode, all clock sources are disabled. timer2/4 will not increment and the state of the module will not change. if the eccp1 pin is driving a value, it will con- tinue to drive that value. when the device wakes up, it will continue from this state. if two-speed start-ups are enabled, the initial start-up frequency from hf-intosc and the postscaler may not be stable immediately. in pri_idle mode, the primary clock will continue to clock the eccp1 module without change. 20.4.8.1 operation with fail-safe clock monitor (fscm) if the fail-safe clock monitor (fscm) is enabled, a clock failure will force the device into the power-managed rc_run mode and the oscfif bit of the pir2 register will be set. the eccp1 will then be clocked from the internal oscillator clock source, which may have a different clock frequency than the primary clock. 20.4.9 effects of a reset both power-on reset and subsequent resets will force all ports to input mode and the eccp registers to their reset states. this forces the eccp module to reset to a state compatible with previous, non-enhanced ccp modules used on other pic18 and pic16 devices.
pic18f66k80 family ds39977d-page 290 ? 2011 microchip technology inc. table 20-3: registers associated with eccp1 module and timer1/2/3/4 file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif rcon ipen sboren cm ri to pd por bor pir3 ? ? rc2if tx2if ctmuif ccp2if ccp1if ? pie3 ? ? rc2ie tx2ie ctmuie ccp2ie ccp1ie ? ipr3 ? ? rc2ip tx2ip ctmuip ccp2ip ccp1ip ? pir4 tmr4if eeif cmp2if cmp1if ? ccp5if ccp4if ccp3if pie4 tmr4ie eeie cmp2ie cmp1ie ? ccp5ie ccp4ie ccp3ie ipr4 tmr4ip eeip cmp2ip cmp1ip ? ccp5ip ccp4ip ccp3ip trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 trise trise7 trise6 trise5 trise4 ? trise2 trise1 trise0 tmr1h timer1 register high byte tmr1l timer1 register low byte tmr2 timer2 register tmr3h timer3 register high byte tmr3l timer3 register low byte tmr4 timer4 register pr2 timer2 period register pr4 timer4 period register t1con tmr1cs1 tmr1cs0 t1ckps1 t1ckps0 soscen t1sync rd16 tmr1on t2con ? t2outps3 t2outps2 t2outps1 t2outps0 tmr2on t2ckps1 t2ckps0 t3con tmr3cs1 tmr3cs0 t3ckps1 t3ckps0 soscen t3sync rd16 tmr3on t4con ? t4outps3 t4outps2 t4outps1 t4outps0 tmr4on t4ckps1 t4ckps0 ccpr1h capture/compare/pwm register 1 high byte ccpr1l capture/compare/pwm register 1 low byte ccpr2h capture/compare/pwm register 2 high byte ccpr2l capture/compare/pwm register 2 low byte ccpr3h capture/compare/pwm register 3 high byte ccpr3l capture/compare/pwm register 3 low byte ccp1con p1m1 p1m0 dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 ccp2con ? ? dc2b1 dc2b0 ccp2m3 ccp2m2 ccp2m1 ccp2m0 ccp3con ? ? dc3b1 dc3b0 ccp3m3 ccp3m2 ccp3m1 ccp3m0 ccptmrs ? ? ? c5tsel c4tsel c3tsel c2tsel c1tsel eccp1as eccp1ase eccp1as2 eccp1as1 eccp1as0 pss1ac1 pss1ac0 pss1bd1 pss1bd0 eccp1del p1rsen p1dc6 p1dc5 p1dc4 p1dc3 p1dc2 p1dc1 p1dc0 pmd0 ccp5md ccp4md ccp3md ccp2md ccp1md uart2md uart1md sspmd note 1: unimplemented on devices with a program memory of 32 kbytes (pic18f25k80 and pic18f46k80).
? 2011 microchip technology inc. ds39977d-page 291 pic18f66k80 family 21.0 master synchronous serial port (mssp) module 21.1 master ssp (mssp) module overview the master synchronous serial port (mssp) module is a serial interface, useful for communicating with other peripheral or microcontroller devices. these peripheral devices may be devices such as serial eeproms, shift registers, display drivers and a/d converters. the mssp module can operate in either of two modes: ? serial peripheral interface (spi) ? inter-integrated circuit (i 2 c?) - full master mode - slave mode (with general address call) the i 2 c interface supports the following modes in hardware: ?master mode ? multi-master mode ? slave mode with 5-bit and 7-bit address masking (with address masking for both 10-bit and 7-bit addressing) 21.2 control registers the mssp module has three associated control regis- ters. these include a status register (sspstat) and two control registers (sspcon1 and sspcon2). the use of these registers and their individual configuration bits differ significantly depending on whether the mssp module is operated in spi or i 2 c mode. additional details are provided under the individual sections. 21.3 spi mode the spi mode allows 8 bits of data to be synchronously transmitted and received simultaneously. all four modes of spi are supported. to accomplish communication, typically three pins are used: ? serial data out (sdo) ? rc5/sdo ? serial data in (sdi) ? rc4/sda/sdi ? serial clock (sck) ? rc3/ref0/scl/sck additionally, a fourth pin may be used when in a slave mode of operation: ? slave select (ss ) ? ra5/an4/c2inb/ hlvdin/t1cki/ss /ctmu1 figure 21-1 shows the block diagram of the mssp module when operating in spi mode. figure 21-1: mssp block diagram (spi mode) ( ) read write internal data bus sspsr reg sspm<3:0> bit 0 shift clock ss control enable edge select clock select tmr2 output t osc prescaler 4, 16, 64 2 edge select 2 4 data to txx/rxx in sspsr tris bit 2 smp:cke sdo sspbuf reg sdi ss sck note: only port i/o names are used in this diagram for the sake of brevity. refer to the text for a full list of multiplexed functions.
pic18f66k80 family ds39977d-page 292 ? 2011 microchip technology inc. 21.3.1 registers the mssp module has four registers for spi mode operation. these are: ? mssp control register 1 (sspcon1) ? mssp status register (sspstat) ? serial receive/transmit buffer register (sspbuf) ? mssp shift register (sspsr) ? not directly accessible sspcon1 and sspstat are the control and status registers in spi mode operation. the sspcon1 register is readable and writable. the lower 6 bits of the sspstat are read-only. the upper two bits of the sspstat are read/write. sspsr is the shift register used for shifting data in or out. sspbuf is the buffer register to which data bytes are written to or read from. in receive operations, sspsr and sspbuf together, create a double-buffered receiver. when sspsr receives a complete byte, it is transferred to sspbuf and the sspif interrupt is set. during transmission, the sspbuf is not double-buffered. a write to sspbuf will write to both sspbuf and sspsr. register 21-1: sspstat: mssp status register (spi mode) r/w-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 smp cke (1) d/a psr/w ua bf bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 smp: sample bit spi master mode: 1 = input data sampled at the end of data output time 0 = input data sampled at the middle of data output time spi slave mode: smp must be cleared when spi is used in slave mode. bit 6 cke: spi clock select bit (1) 1 = transmit occurs on transition from active to idle clock state 0 = transmit occurs on transition from idle to active clock state bit 5 d/a : data/address bit used in i 2 c? mode only. bit 4 p: stop bit used in i 2 c mode only. this bit is cleared when the mssp module is disabled; sspen is cleared. bit 3 s: start bit used in i 2 c mode only. bit 2 r/w : read/write information bit used in i 2 c mode only. bit 1 ua: update address bit used in i 2 c mode only. bit 0 bf: buffer full status bit (receive mode only) 1 = receive complete, sspbuf is full 0 = receive not complete, sspbuf is empty note 1: polarity of clock state is set by the ckp bit (sspcon1<4>).
? 2011 microchip technology inc. ds39977d-page 293 pic18f66k80 family register 21-2: sspcon1: mssp control register 1 (spi mode) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 wcol sspov (1) sspen (2) ckp sspm3 (3) sspm2 (3) sspm1 (3) sspm0 (3) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 wcol: write collision detect bit 1 = the sspbuf register is written while it is still transmitting the previous word (must be cleared in software) 0 = no collision bit 6 sspov: receive overflow indicator bit (1) spi slave mode: 1 = a new byte is received while the sspbuf register is still holding the previous data. in case of over- flow, the data in sspsr is lost. overflow can only occur in slave mode. the user must read the sspbuf, even if only transmitting data, to avoid setting overflow (must be cleared in software). 0 = no overflow bit 5 sspen: master synchronous serial port enable bit (2) 1 = enables the serial port and configures sck, sdo, sdi and ss as serial port pins 0 = disables the serial port and configures these pins as i/o port pins bit 4 ckp: clock polarity select bit 1 = idle state for clock is a high level 0 = idle state for clock is a low level bit 3-0 sspm<3:0>: master synchronous serial port mode select bits (3) 1010 = spi master mode: clock = f osc /8 0101 = spi slave mode: clock = sck pin; s s pin control disabled; s s can be used as i/o pin 0100 = spi slave mode: clock = sck pin; s s pin control enabled 0011 = spi master mode: clock = tmr2 output/2 0010 = spi master mode: clock = f osc /64 0001 = spi master mode: clock = f osc /16 0000 = spi master mode: clock = f osc /4 note 1: in master mode, the overflow bit is not set since each new reception (and transmission) is initiated by writing to the sspbuf register. 2: when enabled, these pins must be properly configured as inputs or outputs. 3: bit combinations not specifically listed here are either reserved or implemented in i 2 c mode only.
pic18f66k80 family ds39977d-page 294 ? 2011 microchip technology inc. 21.3.2 operation when initializing the spi, several options need to be specified. this is done by programming the appropriate control bits (sspcon1<5:0> and sspstat<7:6>). these control bits allow the following to be specified: ? master mode (sck is the clock output) ? slave mode (sck is the clock input) ? clock polarity (idle state of sck) ? data input sample phase (middle or end of data output time) ? clock edge (output data on rising/falling edge of sck) ? clock rate (master mode only) ? slave select mode (slave mode only) the mssp module consists of a transmit/receive shift register (sspsr) and a buffer register (sspbuf). the sspsr shifts the data in and out of the device, msb first. the sspbuf holds the data that was written to the sspsr until the received data is ready. once the 8 bits of data have been received, that byte is moved to the sspbuf register. then, the buffer full detect bit, bf (sspstat<0>), and the interrupt flag bit, sspif, are set. this double-buffering of the received data (sspbuf) allows the next byte to start reception before reading the data that was just received. any write to the sspbuf register during transmission/reception of data will be ignored and the write collision detect bit, wcol (sspcon1<7>), will be set. user software must clear the wcol bit so that it can be determined if the following write(s) to the sspbuf register completed successfully. when the application software is expecting to receive valid data, the sspbuf should be read before the next byte of data to transfer is written to the sspbuf. the buffer full bit, bf (sspstat<0>), indicates when sspbuf has been loaded with the received data (transmission is complete). when the sspbuf is read, the bf bit is cleared. this data may be irrelevant if the spi is only a transmitter. generally, the mssp interrupt is used to determine when the transmission/reception has completed. if the interrupt method is not going to be used, then software polling can be done to ensure that a write collision does not occur. example 21-1 shows the loading of the sspbuf (sspsr) for data transmission. the sspsr is not directly readable or writable and can only be accessed by addressing the sspbuf register. additionally, the sspstat register indicates the various status conditions. 21.3.3 open-drain output option the drivers for the sdo output and sck clock pins can be optionally configured as open-drain outputs. this feature allows the voltage level on the pin to be pulled to a higher level through an external pull-up resistor, and allows the output to communicate with external cir- cuits without the need for additional level shifters. for more information, see section 11.1.3 ?open-drain outputs? . the open-drain output option is controlled by the sspod bit (odcon<7>). setting the sspod bit configures the sdo and sck pins for open-drain operation. example 21-1: loading the sspbuf (sspsr) register loop btfss sspstat, bf ;has data been received (transmit complete)? bra loop ;no movf sspbuf, w ;wreg reg = contents of sspbuf movwf rxdata ;save in user ram, if data is meaningful movf txdata, w ;w reg = contents of txdata movwf sspbuf ;new data to xmit
? 2011 microchip technology inc. ds39977d-page 295 pic18f66k80 family 21.3.4 enabling spi i/o to enable the serial port, mssp enable bit, sspen (sspcon1<5>), must be set. to reset or reconfigure spi mode, clear the sspen bit, reinitialize the sspcon registers and then set the sspen bit. this configures the sdi, sdo, sck and ss pins as serial port pins. for the pins to behave as the serial port func- tion, some must have their data direction bits (in the tris register) appropriately programmed as follows: ? sdi is automatically controlled by the spi module ? sdo must have the trisc<5> bit cleared ? sck (master mode) must have the trisc<3> bit cleared ? sck (slave mode) must have the trisc<3> bit set ?ss must have the trisa<5> bit set any serial port function that is not desired may be overridden by programming the corresponding data direction (tris) register to the opposite value. 21.3.5 typical connection figure 21-2 shows a typical connection between two microcontrollers. the master controller (processor 1) initiates the data transfer by sending the sck signal. data is shifted out of both shift registers on their pro- grammed clock edge and latched on the opposite edge of the clock. both processors should be programmed to the same clock polarity (ckp), then both controllers would send and receive data at the same time. whether the data is meaningful (or dummy data) depends on the application software. this leads to three scenarios for data transmission: ? master sends data ? ? ? slave sends dummy data ? master sends data ? ? ? slave sends data ? master sends dummy data ? ? ? slave sends data figure 21-2: spi master/slave connection serial input buffer (sspbuf) shift register (sspsr) msb lsb sdo sdi processor 1 sck spi master sspm<3:0> = 00xx b serial input buffer (sspbuf) shift register (sspsr) lsb msb sdi sdo processor 2 sck spi slave sspm<3:0> = 010x b serial clock
pic18f66k80 family ds39977d-page 296 ? 2011 microchip technology inc. 21.3.6 master mode the master can initiate the data transfer at any time because it controls the sck. the master determines when the slave (processor 1, figure 21-2 ) is to broadcast data by the software protocol. in master mode, the data is transmitted/received as soon as the sspbuf register is written to. if the spi is only going to receive, the sdo output could be dis- abled (programmed as an input). the sspsr register will continue to shift in the signal present on the sdi pin at the programmed clock rate. as each byte is received, it will be loaded into the sspbuf register as if a normal received byte (interrupts and status bits appropriately set). this could be useful in receiver applications as a ?line activity monitor? mode. the clock polarity is selected by appropriately programming the ckp bit (sspcon1<4>). this then, would give waveforms for spi communication as shown in figure 21-3 , figure 21-5 and figure 21-6 , where the msb is transmitted first. in master mode, the spi clock rate (bit rate) is user-programmable to be one of the following: ?f osc /4 (or t cy ) ?f osc /16 (or 4 ? t cy ) ?f osc /64 (or 16 ? t cy ) ? timer2 output/2 this allows a maximum data rate (at 64 mhz) of 16 mbps. figure 21-3 shows the waveforms for master mode. when the cke bit is set, the sdo data is valid before there is a clock edge on sck. the change of the input sample is shown based on the state of the smp bit. the time when the sspbuf is loaded with the received data is shown. figure 21-3: spi mode waveform (master mode) sck (ckp = 0 sck (ckp = 1 sck (ckp = 0 sck (ckp = 1 four clock modes input sample input sample sdi bit 7 bit 0 sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 sdi sspif (smp = 1 ) (smp = 0 ) (smp = 1 ) cke = 1 ) cke = 0 ) cke = 1 ) cke = 0 ) (smp = 0 ) write to sspbuf sspsr to sspbuf sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 (cke = 0 ) (cke = 1 ) next q4 cycle after q2 ? bit 0
? 2011 microchip technology inc. ds39977d-page 297 pic18f66k80 family 21.3.7 slave mode in slave mode, the data is transmitted and received as the external clock pulses appear on sck. when the last bit is latched, the sspif interrupt flag bit is set. while in slave mode, the external clock is supplied by the external clock source on the sck pin. this external clock must meet the minimum high and low times as specified in the electrical specifications. while in sleep mode, the slave can transmit/receive data. when a byte is received, the device can be configured to wake-up from sleep. 21.3.8 slave select synchronization the ss pin allows a synchronous slave mode. the spi must be in slave mode with the ss pin control enabled (sspcon1<3:0> = 04h). when the ss pin is low, transmission and reception are enabled and the sdo pin is driven. when the ss pin goes high, the sdo pin is no longer driven, even if in the middle of a transmitted byte, and becomes a floating output. external pull-up/pull-down resistors may be desirable depending on the application. when the spi module resets, the bit counter is forced to ? 0 ?. this can be done by either forcing the ss pin to a high level or clearing the sspen bit. to emulate two-wire communication, the sdo pin can be connected to the sdi pin. when the spi needs to operate as a receiver, the sdo pin can be configured as an input. this disables transmissions from the sdo. the sdi can always be left as an input (sdi function) since it cannot create a bus conflict. figure 21-4: slave synchronization waveform note 1: when the spi is in slave mode, with ss pin control enabled (sspcon1<3:0> = 0100 ), the spi module will reset if the ss pin is set to v dd . 2: if the spi is used in slave mode, with cke set, then the ss pin control must be enabled. sck (ckp = 1 sck (ckp = 0 input sample sdi bit 7 sdo bit 7 bit 6 bit 7 sspif interrupt (smp = 0 ) cke = 0 ) cke = 0 ) (smp = 0 ) write to sspbuf sspsr to sspbuf ss flag bit 0 bit 7 bit 0 next q4 cycle after q2 ?
pic18f66k80 family ds39977d-page 298 ? 2011 microchip technology inc. figure 21-5: spi mode waveform (slave mode with cke = 0 ) figure 21-6: spi mode waveform (slave mode with cke = 1 ) sck (ckp = 1 sck (ckp = 0 input sample sdi bit 7 sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 sspif interrupt (smp = 0 ) cke = 0 ) cke = 0 ) (smp = 0 ) write to sspbuf sspsr to sspbuf ss flag optional next q4 cycle after q2 ? bit 0 sck (ckp = 1 sck (ckp = 0 input sample sdi bit 7 bit 0 sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 sspif interrupt (smp = 0 ) cke = 1 ) cke = 1 ) (smp = 0 ) write to sspbuf sspsr to sspbuf ss flag not optional next q4 cycle after q2 ?
? 2011 microchip technology inc. ds39977d-page 299 pic18f66k80 family 21.3.9 operation in power-managed modes in spi master mode, module clocks may be operating at a different speed than when in full-power mode; in the case of the sleep mode, all clocks are halted. in idle modes, a clock is provided to the peripherals. that clock can be from the primary clock source, the secondary clock (sosc oscillator) or the intosc source. see section 3.3 ?clock sources and oscillator switching? for additional information. in most cases, the speed that the master clocks spi data is not important; however, this should be evaluated for each system. if mssp interrupt is enabled, it can wake the controller from sleep mode, or one of the idle modes, when the master completes sending data. if an exit from sleep or idle mode is not desired, mssp interrupts should be disabled. if the sleep mode is selected, all module clocks are halted and the transmission/reception will remain in that state until the device wakes. after the device returns to run mode, the module will resume transmitting and receiving data. in spi slave mode, the spi transmit/receive shift register operates asynchronously to the device. this allows the device to be placed in any power-managed mode and data to be shifted into the spi transmit/receive shift register. when all 8 bits have been received, the mssp interrupt flag bit will be set, and if enabled, will wake the device. 21.3.10 effects of a reset a reset disables the mssp module and terminates the current transfer. 21.3.11 bus mode compatibility table 21-1 shows the compatibility between the standard spi modes, and the states of the ckp and cke control bits. table 21-1: spi bus modes there is also an smp bit which controls when the data is sampled. table 21-2: registers associat ed with spi operation standard spi mode terminology control bits state ckp cke 0, 0 0 1 0, 1 0 0 1, 0 1 1 1, 1 1 0 name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif pir1 pspif adif rc1if tx1if sspif tmr1gif tmr2if tmr1if pie1 pspie adie rc1ie tx1ie sspie tmr1gie tmr2ie tmr1ie ipr1 pspip adip rc1ip tx1ip sspip tmr1gip tmr2ip tmr1ip trisa trisa7 trisa6 trisa5 ? trisa3 trisa2 trisa1 trisa0 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 sspbuf mssp receive buffer/transmit register sspcon1 wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 sspstat smp cke d/a p s r/w ua bf odcon sspod ccp5od ccp4od ccp3od ccp2od ccp1od u2od u1od pmd0 ccp5md ccp4md ccp3md ccp2md ccp1md uart2md uart1md sspmd legend: shaded cells are not used by the mssp module in spi mode.
pic18f66k80 family ds39977d-page 300 ? 2011 microchip technology inc. 21.4 i 2 c mode the mssp module in i 2 c mode fully implements all master and slave functions (including general call support), and provides interrupts on start and stop bits in hardware to determine a free bus (multi-master function). the mssp module implements the standard mode specifications, as well as 7-bit and 10-bit addressing. two pins are used for data transfer: ? serial clock (scl) ? rc3/refo/scl/sck ? serial data (sda) ? rc4/sda/sdi the user must configure these pins as inputs by setting the associated tris bits. figure 21-7: mssp block diagram (i 2 c? mode) 21.4.1 registers the mssp module has seven registers for i 2 c operation. these are: ? mssp control register 1 (sspcon1) ? mssp control register 2 (sspcon2) ? mssp status register (sspstat) ? serial receive/transmit buffer register (sspbuf) ? mssp shift register (sspsr) ? not directly accessible ? mssp address register (sspadd) ?i 2 c slave address mask register (sspmsk) sspcon1, sspcon2 and sspstat are the control and status registers in i 2 c mode operation. the sspcon1 and sspcon2 registers are readable and writable. the lower 6 bits of the sspstat are read-only. the upper two bits of the sspstat are read/write. sspsr is the shift register used for shifting data in or out. sspbuf is the buffer register to which data bytes are written to or read from. sspadd contains the slave device address when the mssp is configured in i 2 c slave mode. when the mssp is configured in master mode, the lower seven bits of sspadd act as the baud rate generator reload value. sspmsk holds the slave address mask value when the module is configured for 7-bit address masking mode. while it is a separate register, it shares the same sfr address as sspadd; it is only accessible when the sspm<3:0> bits are specifically set to permit access. additional details are provided in section 21.4.3.4 ?7-bit address masking mode? . in receive operations, sspsr and sspbuf together, create a double-buffered receiver. when sspsr receives a complete byte, it is transferred to sspbuf and the sspif interrupt is set. during transmission, the sspbuf is not double-buffered. a write to sspbuf will write to both sspbuf and sspsr. read write sspsr reg match detect sspadd reg sspbuf reg internal data bus addr match set, reset s, p bits (sspstat reg) shift clock msb lsb note: only port i/o names are used in this diagram for the sake of brevity. refer to the text for a full list of multiplexed functions. scl sda start and stop bit detect address mask
? 2011 microchip technology inc. ds39977d-page 301 pic18f66k80 family register 21-3: sspstat: mssp status register (i 2 c? mode) r/w-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 smp cke d/a p (1) s (1) r/w (2,3) ua bf bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 smp: slew rate control bit in master or slave mode: 1 = slew rate control disabled for standard speed mode (100 khz and 1 mhz) 0 = slew rate control enabled for high-speed mode (400 khz) bit 6 cke: smbus select bit in master or slave mode: 1 = enable smbus specific inputs 0 = disable smbus specific inputs bit 5 d/a : data/address bit in master mode: reserved. in slave mode: 1 = indicates that the last byte received or transmitted was data 0 = indicates that the last byte received or transmitted was address bit 4 p: stop bit (1) 1 = indicates that a stop bit has been detected last 0 = stop bit was not detected last bit 3 s: start bit (1) 1 = indicates that a start bit has been detected last 0 = start bit was not detected last bit 2 r/w : read/write information bit (2,3) in slave mode: 1 = read 0 = write in master mode: 1 = transmit is in progress 0 = transmit is not in progress bit 1 ua: update address bit (10-bit slave mode only) 1 = indicates that the user needs to update the address in the sspadd register 0 = address does not need to be updated bit 0 bf: buffer full status bit in transmit mode: 1 = sspbuf is full 0 = sspbuf is empty in receive mode: 1 = sspbuf is full (does not include the ack and stop bits) 0 = sspbuf is empty (does not include the ack and stop bits) note 1: this bit is cleared on reset and when sspen is cleared. 2: this bit holds the r/w bit information following the last address match. this bit is only valid from the address match to the next start bit, stop bit or not ack bit. 3: oring this bit with sen, rsen, pen, rcen or acken will indicate if the mssp is in active mode.
pic18f66k80 family ds39977d-page 302 ? 2011 microchip technology inc. register 21-4: sspcon1: ms sp control register 1 (i 2 c? mode) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 wcol sspov sspen (1) ckp sspm3 (2) sspm2 (2) sspm1 (2) sspm0 (2) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 wcol: write collision detect bit in master transmit mode: 1 = a write to the sspbuf register was attempted while the i 2 c conditions were not valid for a transmission to be started (must be cleared in software) 0 = no collision in slave transmit mode: 1 = the sspbuf register is written while it is still transmitting the previous word (must be cleared in software) 0 = no collision in receive mode (master or slave modes): this is a ?don?t care? bit. bit 6 sspov: receive overflow indicator bit in receive mode: 1 = a byte is received while the sspbuf register is still holding the previous byte (must be cleared in software) 0 = no overflow in transmit mode: this is a ?don?t care? bit in transmit mode. bit 5 sspen: master synchronous serial port enable bit (1) 1 = enables the serial port and configures the sda and scl pins as the serial port pins 0 = disables serial port and configures these pins as i/o port pins bit 4 ckp: sck release control bit in slave mode: 1 = releases clock 0 = holds clock low (clock stretch), used to ensure data setup time in master mode: unused in this mode. bit 3-0 sspm<3:0>: master synchronous serial port mode select bits (2) 1111 = i 2 c slave mode, 10-bit address with start and stop bit interrupts enabled 1110 = i 2 c slave mode, 7-bit address with start and stop bit interrupts enabled 1011 = i 2 c firmware controlled master mode (slave idle) 1001 = load sspmsk register at sspadd sfr address (3,4) 1000 = i 2 c master mode, clock = f osc /(4 * (sspadd + 1)) 0111 = i 2 c slave mode, 10-bit address 0110 = i 2 c slave mode, 7-bit address note 1: when enabled, the sda and scl pins must be configured as inputs. 2: bit combinations not specifically listed here are either reserved or implemented in spi mode only. 3: when sspm<3:0> = 1001 , any reads or writes to the sspadd sfr address actually access the sspmsk register. 4: this mode is only available when 7-bit address masking mode is selected (msspmsk configuration bit is ? 1 ?).
? 2011 microchip technology inc. ds39977d-page 303 pic18f66k80 family register 21-5: sspcon2: ms sp control register 2 (i 2 c? master mode) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 gcen ackstat ackdt (1) acken (2) rcen (2) pen (2) rsen (2) sen (2) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 gcen: general call enable bit unused in master mode. bit 6 ackstat: acknowledge status bit (master transmit mode only) 1 = acknowledge was not received from slave 0 = acknowledge was received from slave bit 5 ackdt: acknowledge data bit (master receive mode only) (1) 1 = not acknowledge 0 = acknowledge bit 4 acken: acknowledge sequence enable bit (2) 1 = initiates acknowledge sequence on sda and scl pins and transmit ackdt data bit. automatically cleared by hardware. 0 = acknowledge sequence idle bit 3 rcen: receive enable bit (master receive mode only) (2) 1 = enables receive mode for i 2 c? 0 = receive idle bit 2 pen: stop condition enable bit (2) 1 = initiates stop condition on sda and scl pins. automatically cleared by hardware. 0 = stop condition idle bit 1 rsen: repeated start condition enable bit (2) 1 = initiates repeated start condition on sda and scl pins. automatically cleared by hardware. 0 = repeated start condition idle bit 0 sen: start condition enable bit (2) 1 = initiates start condition on sda and scl pins. automatically cleared by hardware. 0 = start condition idle note 1: value that will be transmitted when the user initiates an acknowledge sequence at the end of a receive. 2: if the i 2 c module is active, these bits may not be set (no spooling) and the sspbuf may not be written (or writes to the sspbuf are disabled).
pic18f66k80 family ds39977d-page 304 ? 2011 microchip technology inc. register 21-6: sspcon2: ms sp control register 2 (i 2 c? slave mode) register 21-7: sspmsk: i 2 c? slave address mask register (7-bit masking mode) (1) r/w-0 r/w-1 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 gcen ackstat ackdt (1) acken (1) rcen (1) pen (1) rsen (1) sen (1) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 gcen: general call enable bit 1 = enables interrupt when a general call address (0000h) is received in the sspsr 0 = general call address disabled bit 6 ackstat: acknowledge status bit unused in slave mode. bit 5 ackdt: acknowledge data bit (master receive mode only) (1) 1 = not acknowledge 0 = acknowledge bit 4 acken: acknowledge sequence enable bit (1) 1 = initiates acknowledge sequence on sda and scl pins and transmits ackdt data bit. automatically cleared by hardware. 0 = acknowledge sequence idle bit 3 rcen: receive enable bit (master receive mode only) (1) 1 = enables receive mode for i 2 c? 0 = receive idle bit 2 pen: stop condition enable bit (1) 1 = initiates stop condition on sda and scl pins. automatically cleared by hardware. 0 = stop condition idle bit 1 rsen: repeated start condition enable bit (1) 1 = initiates repeated start condition on sda and scl pins. automatically cleared by hardware. 0 = repeated start condition idle bit 0 sen: stretch enable bit (1) 1 = clock stretching is enabled for both slave transmit and slave receive (stretch enabled) 0 = clock stretching is disabled note 1: if the i 2 c module is active, this bit may not be set (no spooling) and the sspbuf may not be written (or writes to the sspbuf are disabled). r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 msk7 msk6 msk5 msk4 msk3 msk2 msk1 msk0 (2) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 msk<7:0>: slave address mask select bit 1 = masking of corresponding bit of sspadd enabled 0 = masking of corresponding bit of sspadd disabled note 1: this register shares the same sfr address as sspadd and is only addressable in select mssp operating modes. see section 21.4.3.4 ?7-bit address masking mode? for more details. 2: msk0 is not used as a mask bit in 7-bit addressing.
? 2011 microchip technology inc. ds39977d-page 305 pic18f66k80 family 21.4.2 operation the mssp module functions are enabled by setting the mssp enable bit, sspen (sspcon1<5>). the sspcon1 register allows control of the i 2 c operation. four mode selection bits (sspcon1<3:0>) allow one of the following i 2 c modes to be selected: ?i 2 c master mode, clock ?i 2 c slave mode (7-bit address) ?i 2 c slave mode (10-bit address) ?i 2 c slave mode (7-bit address) with start and stop bit interrupts enabled ?i 2 c slave mode (10-bit address) with start and stop bit interrupts enabled ?i 2 c firmware controlled master mode, slave is idle selection of any i 2 c mode with the sspen bit set forces the scl and sda pins to be open-drain, provided these pins are programmed as inputs by setting the appropriate trisc bit. to ensure proper operation of the module, pull-up resistors must be provided externally to the scl and sda pins. 21.4.3 slave mode in slave mode, the scl and sda pins must be configured as inputs (trisc<4:3> set). the mssp module will override the input state with the output data when required (slave-transmitter). the i 2 c slave mode hardware will always generate an interrupt on an address match. address masking will allow the hardware to generate an interrupt for more than one address (up to 31 in 7-bit addressing and up to 63 in 10-bit addressing). through the mode select bits, the user can also choose to interrupt on start and stop bits. when an address is matched, or the data transfer after an address match is received, the hardware auto- matically will generate the acknowledge (ack ) pulse and load the sspbuf register with the received value currently in the sspsr register. any combination of the following conditions will cause the mssp module not to give this ack pulse: ? the buffer full bit, bf (sspstat<0>), was set before the transfer was received. ? the overflow bit, sspov (sspcon1<6>), was set before the transfer was received. in this case, the sspsr register value is not loaded into the sspbuf, but bit, sspif, is set. the bf bit is cleared by reading the sspbuf register, while bit, sspov, is cleared through software. the scl clock input must have a minimum high and low for proper operation. the high and low times of the i 2 c specification, as well as the requirement of the mssp module, are shown in timing parameter 100 and parameter 101. 21.4.3.1 addressing once the mssp module has been enabled, it waits for a start condition to occur. following the start condition, the 8 bits are shifted into the sspsr register. all incom- ing bits are sampled with the rising edge of the clock (scl) line. the value of register, sspsr<7:1>, is com- pared to the value of the sspadd register. the address is compared on the falling edge of the eighth clock (scl) pulse. if the addresses match and the bf and sspov bits are clear, the following events occur: 1. the sspsr register value is loaded into the sspbuf register. 2. the buffer full bit, bf, is set. 3. an ack pulse is generated. 4. the mssp interrupt flag bit, sspif, is set (and interrupt is generated, if enabled) on the falling edge of the ninth scl pulse. in 10-bit addressing mode, two address bytes need to be received by the slave. the five most significant bits (msbs) of the first address byte specify if this is a 10-bit address. the r/w (sspstat<2>) bit must specify a write so the slave device will receive the second address byte. for a 10-bit address, the first byte would equal ? 11110 a9 a8 0 ?, where ? a9 ? and ? a8 ? are the two msbs of the address. the sequence of events for 10-bit addressing is as follows, with steps, 7 through 9, for the slave-transmitter: 1. receive first (high) byte of address (bits, sspif, bf and ua, are set on address match). 2. update the sspadd register with second (low) byte of address (clears bit, ua, and releases the scl line). 3. read the sspbuf register (clears bit, bf) and clear flag bit, sspif. 4. receive second (low) byte of address (bits, sspif, bf and ua, are set). 5. update the sspadd register with the first (high) byte of address. if match releases scl line, this will clear bit, ua. 6. read the sspbuf register (clears bit, bf) and clear flag bit sspif. 7. receive repeated start condition. 8. receive first (high) byte of address (bits, sspif and bf, are set). 9. read the sspbuf register (clears bit, bf) and clear flag bit, sspif.
pic18f66k80 family ds39977d-page 306 ? 2011 microchip technology inc. 21.4.3.2 address masking modes masking an address bit causes that bit to become a ?don?t care?. when one address bit is masked, two addresses will be acknowledged and cause an interrupt. it is possible to mask more than one address bit at a time, which greatly expands the number of addresses acknowledged. the i 2 c slave behaves the same way, whether address masking is used or not. however, when address masking is used, the i 2 c slave can acknowledge multiple addresses and cause interrupts. when this occurs, it is necessary to determine which address caused the interrupt by checking the sspbuf. the pic18f66k80 family of devices is capable of using two different address masking modes in i 2 c slave operation: 5-bit address masking and 7-bit address masking. the masking mode is selected at device configuration using the msspmsk configuration bit. the default device configuration is 7-bit address masking. both masking modes, in turn, support address masking of 7-bit and 10-bit addresses. the combination of masking modes and addresses provide different ranges of acknowledgable addresses for each combination. while both masking modes function in roughly the same manner, the way they use address masks are different. 21.4.3.3 5-bit address masking mode as the name implies, 5-bit address masking mode uses an address mask of up to 5 bits to create a range of addresses to be acknowledged, using bits, 5 through 1, of the incoming address. this allows the module to acknowledge up to 31 addresses when using 7-bit addressing, or 63 addresses with 10-bit addressing (see example 21-2 ). this masking mode is selected when the msspmsk configuration bit is programmed (? 0 ?). the address mask in this mode is stored in the sspcon2 register, which stops functioning as a con- trol register in i 2 c slave mode ( register 21-6 ). in 7-bit addressing mode, address mask bits, admsk<5:1> (sspcon2<5:1>), mask the corresponding address bits in the sspadd register. for any admsk bits that are set (admsk = 1 ), the corresponding address bit is ignored (sspadd = x ). for the module to issue an address acknowledge, it is sufficient to match only on addresses that do not have an active address mask. in 10-bit addressing mode, bits, admsk<5:2>, mask the corresponding address bits in the sspadd regis- ter. in addition, admsk1 simultaneously masks the two lsbs of the address (sspadd<1:0>). for any admsk bits that are active (admsk = 1 ), the correspond- ing address bit is ignored (spxadd = x ). also note that although in 10-bit addressing mode, the upper address bits reuse part of the sspadd register bits. the address mask bits do not interact with those bits; they only affect the lower address bits. example 21-2: address masking examples in 5-bit masking mode note 1: admsk1 masks the two least significant bits of the address. 2: the two most significant bits of the address are not affected by address masking. 7-bit addressing: sspadd<7:1>= a0h ( 1010000 ) (sspadd<0> is assumed to be ? 0 ?) admsk<5:1> = 00111 addresses acknowledged: a0h, a2h, a4h, a6h, a8h, aah, ach, aeh 10-bit addressing: sspadd<7:0> = a0h ( 10100000 ) (the two msb of the address are ignored in this example, since they are not affected by masking) admsk<5:1> = 00111 addresses acknowledged: a0h, a1h, a2h, a3h, a4h, a5h, a6h, a7h, a8h, a9h, aah, abh, ach, adh, aeh, afh
? 2011 microchip technology inc. ds39977d-page 307 pic18f66k80 family 21.4.3.4 7-bit address masking mode unlike 5-bit masking, 7-bit address masking mode uses a mask of up to 8 bits (in 10-bit addressing) to define a range of addresses that can be acknowl- edged, using the lowest bits of the incoming address. this allows the module to acknowledge up to 127 different addresses with 7-bit addressing, or 255 with 10-bit addressing (see example 21-3 ). this mode is the default configuration of the module, which is selected when msspmsk is unprogrammed (? 1 ?). the address mask for 7-bit address masking mode is stored in the sspmsk register, instead of the sspcon2 register. sspmsk is a separate hardware register within the module, but it is not directly address- able. instead, it shares an address in the sfr space with the sspadd register. to access the sspmsk reg- ister, it is necessary to select mssp mode, ? 1001 ? (sspcon1<3:0> = 1001 ) and then read or write to the location of sspadd. to use 7-bit address masking mode, it is necessary to initialize sspmsk with a value before selecting the i 2 c slave addressing mode. thus, the required sequence of events is: 1. select sspmsk access mode (sspcon2<3:0> = 1001 ). 2. write the mask value to the appropriate sspadd register address (fc8h). 3. set the appropriate i 2 c slave mode (sspcon2<3:0> = 0111 for 10-bit addressing, 0110 for 7-bit addressing). setting or clearing mask bits in sspmsk behaves in the opposite manner of the admsk bits in 5-bit address masking mode. that is, clearing a bit in sspmsk causes the corresponding address bit to be masked; setting the bit requires a match in that position. sspmsk resets to all ? 1 ?s upon any reset condition and, therefore, has no effect on the standard mssp operation until written with a mask value. with 7-bit addressing, sspmsk<7:1> bits mask the corresponding address bits in the sspadd register. for any sspmsk bits that are active (sspmsk = 0 ), the corresponding sspadd address bit is ignored (sspadd = x ). for the mod- ule to issue an address acknowledge, it is sufficient to match only on addresses that do not have an active address mask. with 10-bit addressing, sspmsk<7:0> bits mask the corresponding address bits in the sspadd register. for any sspmsk bits that are active (= 0 ), the corresponding sspadd address bit is ignored (sspadd = x ). example 21-3: address masking examples in 7-bit masking mode note: the two most significant bits of the address are not affected by address masking. 7-bit addressing: sspadd<7:1> = 1010 000 sspmsk<7:1> = 1111 001 addresses acknowledged = ach, a8h, a4h, a0h 10-bit addressing: sspadd<7:0> = 1010 0000 (the two msb are ignored in this example since they are not affected) sspmsk<5:1> = 1111 0011 addresses acknowledged = ach, a8h, a4h, a0h
pic18f66k80 family ds39977d-page 308 ? 2011 microchip technology inc. 21.4.3.5 reception when the r/w bit of the address byte is clear and an address match occurs, the r/w bit of the sspstat register is cleared. the received address is loaded into the sspbuf register and the sda line is held low (ack ). when the address byte overflow condition exists, then the no acknowledge (ack ) pulse is given. an overflow condition is defined as either bit, bf (sspstat<0>), is set or bit, sspov (sspcon1<6>), is set. an mssp interrupt is generated for each data transfer byte. the interrupt flag bit, sspif, must be cleared in software. the sspstat register is used to determine the status of the byte. if sen is enabled (sspcon2<0> = 1 ), scl will be held low (clock stretch) following each data transfer. the clock must be released by setting bit, ckp (sspcon1<4>). see section 21.4.4 ?clock stretching? for more details. 21.4.3.6 transmission when the r/w bit of the incoming address byte is set and an address match occurs, the r/w bit of the sspstat register is set. the received address is loaded into the sspbuf register. the ack pulse will be sent on the ninth bit and pin scl is held low regard- less of sen (see section 21.4.4 ?clock stretching? for more details). by stretching the clock, the master will be unable to assert another clock pulse until the slave is done preparing the transmit data. the transmit data must be loaded into the sspbuf register, which also loads the sspsr register. then, the scl pin should be enabled by setting bit, ckp (sspcon1<4>). the eight data bits are shifted out on the falling edge of the scl input. this ensures that the sda signal is valid during the scl high time ( figure 21-10 ). the ack pulse from the master-receiver is latched on the rising edge of the ninth scl input pulse. if the sda line is high (not ack ), then the data transfer is com- plete. in this case, when the ack is latched by the slave, the slave logic is reset and the slave monitors for another occurrence of the start bit. if the sda line was low (ack ), the next transmit data must be loaded into the sspbuf register. again, the scl pin must be enabled by setting bit, ckp. an mssp interrupt is generated for each data transfer byte. the sspif bit must be cleared in software and the sspstat register is used to determine the status of the byte. the sspif bit is set on the falling edge of the ninth clock pulse.
? 2011 microchip technology inc. ds39977d-page 309 pic18f66k80 family figure 21-8: i 2 c? slave mode timing with sen = 0 (reception, 7-bit address) sda scl sspif (pir1<3> or pir3<7>) bf (sspstat<0>) sspov (sspcon1<6>) s 1 2 34 567 89 1 2 34 5 67 89 1 23 45 7 89 p a7 a6 a5 a4 a3 a2 a1 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d1 d0 ack receiving data ack receiving data r/w = 0 ack receiving address cleared in software sspbuf is read bus master terminates transfer sspov is set because sspbuf is still full. ack is not sent. d2 6 ckp (sspcon<4>) (ckp does not reset to ? 0 ? when sen = 0 )
pic18f66k80 family ds39977d-page 310 ? 2011 microchip technology inc. figure 21-9: i 2 c? slave mode timing with sen = 0 and admsk<5:1> = 01011 (reception, 7-bit address) sda scl sspif (pir1<3> or pir3<7>) bf (sspstat<0>) sspov (sspcon1<6>) s 12345678912345678912345 789 p a7 a6 a5 x a3 x x d7d6d5d4d3d2d1 d0 d7d6d5d4d3 d1d0 ack receiving data ack receiving data r/w = 0 ack receiving address cleared in software sspbuf is read bus master terminates transfer sspov is set because sspbuf is still full. ack is not sent. d2 6 ckp (sspcon<4>) (ckp does not reset to ? 0 ? when sen = 0 ) note 1: x = don?t care (i.e., address bit can either be a ? 1 ? or a ? 0 ?). 2: in this example, an address equal to a7.a6.a5.x.a3.x.x will be acknowledged and cause an interrupt.
? 2011 microchip technology inc. ds39977d-page 311 pic18f66k80 family figure 21-10: i 2 c? slave mode timing (transmission, 7-bit address) sda scl bf (sspstat<0>) a6 a5 a4 a3 a2 a1 d6 d5 d4 d3 d2 d1 d0 1 2 3 4 5 6 7 8 2 3 4 5 6 7 8 9 sspbuf is written in software cleared in software data in sampled s ack transmitting data r/w = 1 ack receiving address a7 d7 9 1 d6 d5 d4 d3 d2 d1 d0 2 3 4 5 6 7 8 9 sspbuf is written in software cleared in software from sspif isr transmitting data d7 1 ckp (sspcon<4>) p ack ckp is set in software ckp is set in software scl held low while cpu responds to sspif sspif (pir1<3> or pir3<7>) from sspif isr clear by reading
pic18f66k80 family ds39977d-page 312 ? 2011 microchip technology inc. figure 21-11: i 2 c? slave mode timing with sen = 0 and admsk<5:1> = 01001 (reception, 10-bit address) sda scl sspif (pir1<3> or pir3<7>) bf (sspstat<0>) s 123456789 123456789 12345 789 p 1 1 1 1 0 a9 a8 a7 a6 a5 x a3 a2 x x d7 d6 d5 d4 d3 d1 d0 receive data byte ack r/w = 0 ack receive first byte of address cleared in software d2 6 cleared in software receive second byte of address cleared by hardware when sspadd is updated with low byte of address ua (sspstat<1>) clock is held low until update of sspadd has taken place ua is set indicating that the sspadd needs to be updated ua is set indicating that sspadd needs to be updated cleared by hardware when sspadd is updated with high byte of address sspbuf is written with contents of sspsr dummy read of sspbuf to clear bf flag ack ckp (sspcon<4>) 12345 789 d7 d6 d5 d4 d3 d1 d0 receive data byte bus master terminates transfer d2 6 ack cleared in software cleared in software sspov (sspcon1<6>) sspov is set because sspbuf is still full. ack is not sent. (ckp does not reset to ? 0 ? when sen = 0 ) clock is held low until update of sspadd has taken place note 1: x = don?t care (i.e., address bit can either be a ? 1 ? or a ? 0 ?). 2: in this example, an address equal to a9.a8.a7.a6.a5 .x.a3.a2.x.x will be acknowl edged and cause an interrupt. 3: note that the most significant bits of the address are not affected by the bit masking.
? 2011 microchip technology inc. ds39977d-page 313 pic18f66k80 family figure 21-12: i 2 c? slave mode timing with sen = 0 (reception, 10-bit address) sda scl sspif (pir1<3> or pir3<7>) bf (sspstat<0>) s 123456789 123456789 12345 789 p 1 1 1 1 0 a9a8 a7 a6a5 a4a3a2a1 a0 d7 d6d5d4d3 d1d0 receive data byte ack r/w = 0 ack receive first byte of address cleared in software d2 6 cleared in software receive second byte of address cleared by hardware when sspadd is updated with low byte of address ua (sspstat<1>) clock is held low until update of sspadd has taken place ua is set indicating that the sspadd needs to be updated ua is set indicating that sspadd needs to be updated cleared by hardware when sspadd is updated with high byte of address sspbuf is written with contents of sspsr dummy read of sspbuf to clear bf flag ack ckp (sspcon<4>) 12345 789 d7 d6 d5 d4 d3 d1 d0 receive data byte bus master terminates transfer d2 6 ack cleared in software cleared in software sspov (sspcon1<6>) sspov is set because sspbuf is still full. ack is not sent. (ckp does not reset to ? 0 ? when sen = 0 ) clock is held low until update of sspadd has taken place
pic18f66k80 family ds39977d-page 314 ? 2011 microchip technology inc. figure 21-13: i 2 c? slave mode timing (transmission, 10-bit address) sda scl sspif (pir1<3> or pir3<7>) bf (sspstat<0>) s 1234 5 6789 1 2345 678 9 12345 7 89 p 1 1 1 1 0 a9a8 a7 a6a5a4a3a2a1a0 1 1 1 1 0 a8 r/w = 1 ack ack r/w = 0 ack receive first byte of address cleared in software bus master terminates transfer a9 6 receive second byte of address cleared by hardware when sspadd is updated with low byte of address ua (sspstat<1>) clock is held low until update of sspadd has taken place ua is set indicating that the sspadd needs to be updated ua is set indicating that sspadd needs to be updated cleared by hardware when sspadd is updated with high byte of address. sspbuf is written with contents of sspsr dummy read of sspbuf to clear bf flag receive first byte of address 12345 789 d7 d6 d5 d4 d3 d1 ack d2 6 transmitting data byte d0 dummy read of sspbuf to clear bf flag sr cleared in software write of sspbuf initiates transmit cleared in software completion of clears bf flag ckp (sspcon1<4>) ckp is set in software ckp is automatically cleared in hardware, holding scl low clock is held low until update of sspadd has taken place data transmission clock is held low until ckp is set to ? 1 ? third address sequence bf flag is clear at the end of the
? 2011 microchip technology inc. ds39977d-page 315 pic18f66k80 family 21.4.4 clock stretching both 7-bit and 10-bit slave modes implement automatic clock stretching during a transmit sequence. the sen bit (sspcon2<0>) allows clock stretching to be enabled during receives. setting sen will cause the scl pin to be held low at the end of each data receive sequence. 21.4.4.1 clock stretching for 7-bit slave receive mode (sen = 1 ) in 7-bit slave receive mode, on the falling edge of the ninth clock at the end of the ack sequence, if the bf bit is set, the ckp bit in the sspcon1 register is automatically cleared, forcing the scl output to be held low. the ckp bit being cleared to ? 0 ? will assert the scl line low. the ckp bit must be set in the user?s isr before reception is allowed to continue. by holding the scl line low, the user has time to service the isr and read the contents of the sspbuf before the master device can initiate another receive sequence. this will prevent buffer overruns from occurring (see figure 21-15 ). 21.4.4.2 clock stretching for 10-bit slave receive mode (sen = 1 ) in 10-bit slave receive mode, during the address sequence, clock stretching automatically takes place but ckp is not cleared. during this time, if the ua bit is set after the ninth clock, clock stretching is initiated. the ua bit is set after receiving the upper byte of the 10-bit address and following the receive of the second byte of the 10-bit address with the r/w bit cleared to ? 0 ?. the release of the clock line occurs upon updating sspadd. clock stretching will occur on each data receive sequence as described in 7-bit mode. 21.4.4.3 clock stretching for 7-bit slave transmit mode the 7-bit slave transmit mode implements clock stretching by clearing the ckp bit after the falling edge of the ninth clock if the bf bit is clear. this occurs regardless of the state of the sen bit. the user?s isr must set the ckp bit before transmis- sion is allowed to continue. by holding the scl line low, the user has time to service the isr and load the contents of the sspbuf before the master device can initiate another transmit sequence (see figure 21-10 ). 21.4.4.4 clock stretching for 10-bit slave transmit mode in 10-bit slave transmit mode, clock stretching is controlled during the first two address sequences by the state of the ua bit, just as it is in 10-bit slave receive mode. the first two addresses are followed by a third address sequence, which contains the high-order bits of the 10-bit address and the r/w bit set to ? 1 ?. after the third address sequence is performed, the ua bit is not set, the module is now configured in transmit mode and clock stretching is controlled by the bf flag as in 7-bit slave transmit mode (see figure 21-13 ). note 1: if the user reads the contents of the sspbuf before the falling edge of the ninth clock, thus clearing the bf bit, the ckp bit will not be cleared and clock stretching will not occur. 2: the ckp bit can be set in software, regardless of the state of the bf bit. the user should be careful to clear the bf bit in the isr before the next receive sequence in order to prevent an overflow condition. note: if the user polls the ua bit and clears it by updating the sspadd register before the falling edge of the ninth clock occurs, and if the user hasn?t cleared the bf bit by reading the sspbuf register before that time, then the ckp bit will still not be asserted low. clock stretching on the basis of the state of the bf bit only occurs during a data sequence, not an address sequence. note 1: if the user loads the contents of sspbuf, setting the bf bit before the falling edge of the ninth clock, the ckp bit will not be cleared and clock stretching will not occur. 2: the ckp bit can be set in software regardless of the state of the bf bit.
pic18f66k80 family ds39977d-page 316 ? 2011 microchip technology inc. 21.4.4.5 clock synchronization and the ckp bit when the ckp bit is cleared, the scl output is forced to ? 0 ?. however, clearing the ckp bit will not assert the scl output low until the scl output is already sampled low. therefore, the ckp bit will not assert the scl line until an external i 2 c master device has already asserted the scl line. the scl output will remain low until the ckp bit is set and all other devices on the i 2 c bus have deasserted scl. this ensures that a write to the ckp bit will not violate the minimum high time requirement for scl (see figure 21-14 ). figure 21-14: clock synchronization timing sda scl dx ? 1 dx wr q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 sspcon1 ckp master device deasserts clock master device asserts clock
? 2011 microchip technology inc. ds39977d-page 317 pic18f66k80 family figure 21-15: i 2 c? slave mode timing with sen = 1 (reception, 7-bit address) sda scl sspif (pir1<3> or pir3<7>) bf (sspstat<0>) sspov (sspcon1<6>) s 1 234 56 7 8 9 1 2345 67 89 1 23 45 7 89 p a7 a6 a5 a4 a3 a2 a1 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d1 d0 ack receiving data ack receiving data r/w = 0 ack receiving address cleared in software sspbuf is read bus master terminates transfer sspov is set because sspbuf is still full. ack is not sent. d2 6 ckp (sspcon<4>) ckp written to ? 1 ? in if bf is cleared prior to the falling edge of the 9th clock, ckp will not be reset to ? 0 ? and no clock stretching will occur software clock is held low until ckp is set to ? 1 ? clock is not held low because buffer full bit is clear prior to falling edge of 9th clock clock is not held low because ack = 1 bf is set after falling edge of the 9th clock, ckp is reset to ? 0 ? and clock stretching occurs
pic18f66k80 family ds39977d-page 318 ? 2011 microchip technology inc. figure 21-16: i 2 c? slave mode timing with sen = 1 (reception, 10-bit address) sda scl sspif (pir1<3> or pir3<7>) bf (sspstat<0>) s 123456789 123456789 12345 789 p 1 1 1 1 0 a9a8 a7 a6a5a4a3a2a1 a0 d7d6d5d4d3 d1d0 receive data byte ack r/w = 0 ack receive first byte of address cleared in software d2 6 cleared in software receive second byte of address cleared by hardware when sspadd is updated with low byte of address after falling edge ua (sspstat<1>) clock is held low until update of sspadd has taken place ua is set indicating that the sspadd needs to be updated ua is set indicating that sspadd needs to be updated cleared by hardware when sspadd is updated with high byte of address after falling edge sspbuf is written with contents of sspsr dummy read of sspbuf to clear bf flag ack ckp (sspcon<4>) 12345 789 d7 d6 d5 d4 d3 d1 d0 receive data byte bus master terminates transfer d2 6 ack cleared in software cleared in software sspov (sspcon1<6>) ckp written to ? 1 ? note: an update of the sspadd register before the falling edge of the ninth clock will have no effect on ua and ua will remain set. note: an update of the sspadd register before the falling edge of the ninth clock will have no effect on ua and ua will remain set. in software clock is held low until update of sspadd has taken place of ninth clock of ninth clock sspov is set because sspbuf is still full. ack is not sent. dummy read of sspbuf to clear bf flag clock is held low until ckp is set to ? 1 ? clock is not held low because ack = 1
? 2011 microchip technology inc. ds39977d-page 319 pic18f66k80 family 21.4.5 general call address support the addressing procedure for the i 2 c bus is such that the first byte after the start condition usually determines which device will be the slave addressed by the master. the exception is the general call address which can address all devices. when this address is used, all devices should, in theory, respond with an acknowledge. the general call address is one of eight addresses reserved for specific purposes by the i 2 c protocol. it consists of all ? 0 ?s with r/w = 0 . the general call address is recognized when the general call enable bit, gcen, is enabled (sspcon2<7> set). following a start bit detect, eight bits are shifted into the sspsr and the address is compared against the sspadd. it is also compared to the general call address and fixed in hardware. if the general call address matches, the sspsr is transferred to the sspbuf, the bf flag bit is set (eighth bit), and on the falling edge of the ninth bit (ack bit), the sspif interrupt flag bit is set. when the interrupt is serviced, the source for the interrupt can be checked by reading the contents of the sspbuf. the value can be used to determine if the address was device-specific or a general call address. in 10-bit addressing mode, the sspadd is required to be updated for the second half of the address to match and the ua bit is set (sspstat<1>). if the general call address is sampled when the gcen bit is set, while the slave is configured in 10-bit addressing mode, then the second half of the address is not necessary, the ua bit will not be set and the slave will begin receiving data after the acknowledge ( figure 21-17 ). figure 21-17: slave mode general call address sequence (7 or 10-bit addressing mode) sda scl s sspif bf (sspstat<0>) sspov (sspcon1<6>) cleared in software sspbuf is read r/w = 0 ack general call address address is compared to general call address gcen (sspcon2<7>) receiving data ack 123456789123456789 d7 d6 d5 d4 d3 d2 d1 d0 after ack , set interrupt ? 0 ? ? 1 ?
pic18f66k80 family ds39977d-page 320 ? 2011 microchip technology inc. 21.4.6 master mode master mode is enabled by setting and clearing the appropriate sspm bits in sspcon1 and by setting the sspen bit. in master mode, the scl and sda lines are manipulated by the mssp hardware if the tris bits are set. master mode of operation is supported by interrupt generation on the detection of the start and stop conditions. the stop (p) and start (s) bits are cleared from a reset or when the mssp module is disabled. control of the i 2 c bus may be taken when the p bit is set, or the bus is idle, with both the s and p bits clear. in firmware controlled master mode, user code conducts all i 2 c bus operations based on start and stop bit conditions. once master mode is enabled, the user has six options. 1. assert a start condition on sda and scl. 2. assert a repeated start condition on sda and scl. 3. write to the sspbuf register initiating transmission of data/address. 4. configure the i 2 c port to receive data. 5. generate an acknowledge condition at the end of a received byte of data. 6. generate a stop condition on sda and scl. the following events will cause the mssp interrupt flag bit, sspif, to be set (and mssp interrupt, if enabled): ? start condition ? stop condition ? data transfer byte transmitted/received ? acknowledge transmitted ? repeated start figure 21-18: mssp block diagram (i 2 c? master mode) note: the mssp module, when configured in i 2 c master mode, does not allow queueing of events. for instance, the user is not allowed to initiate a start condition and immediately write the sspbuf register to initiate transmission before the start condition is complete. in this case, the sspbuf will not be written to and the wcol bit will be set, indicating that a write to the sspbuf did not occur. read write sspsr start bit, stop bit, sspbuf internal data bus set/reset s, p (sspstat), wcol (sspcon1); shift clock msb lsb sda acknowledge generate stop bit detect write collision detect clock arbitration state counter for end of xmit/rcv scl scl in bus collision sda in receive enable clock cntl clock arbitrate/wcol detect (hold off clock source) sspadd<6:0> baud set sspif, bclif; reset ackstat, pen (sspcon2) rate generator sspm<3:0> start bit detect
? 2011 microchip technology inc. ds39977d-page 321 pic18f66k80 family 21.4.6.1 i 2 c? master mode operation the master device generates all of the serial clock pulses and the start and stop conditions. a transfer is ended with a stop condition or with a repeated start condition. since the repeated start condition is also the beginning of the next serial transfer, the i 2 c bus will not be released. in master transmitter mode, serial data is output through sda while scl outputs the serial clock. the first byte transmitted contains the slave address of the receiving device (7 bits) and the read/write (r/w ) bit. in this case, the r/w bit will be logic ? 0 ?. serial data is transmitted, 8 bits at a time. after each byte is transmit- ted, an acknowledge bit is received. start and stop conditions are output to indicate the beginning and the end of a serial transfer. in master receive mode, the first byte transmitted contains the slave address of the transmitting device (7 bits) and the r/w bit. in this case, the r/w bit will be logic ? 1 ?. thus, the first byte transmitted is a 7-bit slave address, followed by a ? 1 ? to indicate the receive bit. serial data is received via sda, while scl outputs the serial clock. serial data is received, 8 bits at a time. after each byte is received, an acknowledge bit is transmitted. start and stop conditions indicate the beginning and end of transmission. the baud rate generator, used for the spi mode operation, is used to set the scl clock frequency for either 100 khz, 400 khz or 1 mhz i 2 c operation. see section 21.4.7 ?baud rate? for more details. a typical transmit sequence would go as follows: 1. the user generates a start condition by setting the start enable bit, sen (sspcon2<0>). 2. sspif is set. the mssp module will wait the required start time before any other operation takes place. 3. the user loads the sspbuf with the slave address to transmit. 4. address is shifted out the sda pin until all 8 bits are transmitted. 5. the mssp module shifts in the ack bit from the slave device and writes its value into the sspcon2 register (sspcon2<6>). 6. the mssp module generates an interrupt at the end of the ninth clock cycle by setting the sspif bit. 7. the user loads the sspbuf with eight bits of data. 8. data is shifted out the sda pin until all 8 bits are transmitted. 9. the mssp module shifts in the ack bit from the slave device and writes its value into the sspcon2 register (sspcon2<6>). 10. the mssp module generates an interrupt at the end of the ninth clock cycle by setting the sspif bit. 11. the user generates a stop condition by setting the stop enable bit, pen (sspcon2<2>). 12. interrupt is generated once the stop condition is complete.
pic18f66k80 family ds39977d-page 322 ? 2011 microchip technology inc. 21.4.7 baud rate in i 2 c master mode, the baud rate generator (brg) reload value is placed in the lower 7 bits of the sspadd register ( figure 21-19 ). when a write occurs to sspbuf, the baud rate generator will automatically begin counting. the brg counts down to 0 and stops until another reload has taken place. the brg count is decremented twice per instruction cycle (t cy ) on the q2 and q4 clocks. in i 2 c master mode, the brg is reloaded automatically. once the given operation is complete (i.e., transmis- sion of the last data bit is followed by ack ), the internal clock will automatically stop counting and the scl pin will remain in its last state. table 21-3 demonstrates clock rates based on instruction cycles and the brg value loaded into sspadd. the sspadd brg value of 00h is not supported. figure 21-19: baud rate generator block diagram table 21-3: i 2 c? clock rate w/brg f osc f cy f cy * 2 brg value f scl (2 rollovers of brg) 40 mhz 10 mhz 20 mhz 18h 400 khz (1) 40 mhz 10 mhz 20 mhz 1fh 312.5 khz 40 mhz 10 mhz 20 mhz 63h 100 khz 16 mhz 4 mhz 8 mhz 09h 400 khz (1) 16 mhz 4 mhz 8 mhz 0ch 308 khz 16 mhz 4 mhz 8 mhz 27h 100 khz 4 mhz 1 mhz 2 mhz 02h 333 khz (1) 4 mhz 1 mhz 2 mhz 09h 100 khz 16 mhz (2) 4 mhz 8 mhz 03h 1 mhz (1) note 1: the i 2 c interface does not conform to the 400 khz i 2 c specification (which applies to rates greater than 100 khz) in all details, but may be used with care where higher rates are required by the application. 2: a minimum 16-mhz f osc is required for 1 mhz i 2 c. sspm<3:0> brg down counter clko f osc /4 sspadd<6:0> sspm<3:0> scl reload control reload
? 2011 microchip technology inc. ds39977d-page 323 pic18f66k80 family 21.4.7.1 clock arbitration clock arbitration occurs when the master, during any receive, transmit or repeated start/stop condition, deasserts the scl pin (scl allowed to float high). when the scl pin is allowed to float high, the baud rate generator (brg) is suspended from counting until the scl pin is actually sampled high. when the scl pin is sampled high, the baud rate generator is reloaded with the contents of sspadd<6:0> and begins counting. this ensures that the scl high time will always be at least one brg rollover count in the event that the clock is held low by an external device ( figure 21-20 ). figure 21-20: baud rate generator timing with clock arbitration sda scl scl deasserted but slave holds dx ? 1 dx brg scl is sampled high, reload takes place and brg starts its count 03h 02h 01h 00h (hold off) 03h 02h reload brg value scl low (clock arbitration) scl allowed to transition high brg decrements on q2 and q4 cycles
pic18f66k80 family ds39977d-page 324 ? 2011 microchip technology inc. 21.4.8 i 2 c? master mode start condition timing to initiate a start condition, the user sets the start enable bit, sen (sspcon2<0>). if the sda and scl pins are sampled high, the baud rate generator is reloaded with the contents of sspadd<6:0> and starts its count. if scl and sda are both sampled high when the baud rate generator times out (t brg ), the sda pin is driven low. the action of the sda being driven low while scl is high is the start condition and causes the s bit (sspstat<3>) to be set. following this, the baud rate generator is reloaded with the contents of sspadd<6:0> and resumes its count. when the baud rate generator times out (t brg ), the sen bit (sspcon2<0>) will be automatically cleared by hardware. the baud rate generator is suspended, leaving the sda line held low and the start condition is complete. 21.4.8.1 wcol status flag if the user writes the sspbuf when a start sequence is in progress, the wcol bit is set and the contents of the buffer are unchanged (the write doesn?t occur). figure 21-21: first start bit timing note: if, at the beginning of the start condition, the sda and scl pins are already sampled low or if during the start condi- tion, the scl line is sampled low before the sda line is driven low, a bus collision occurs, the bus collision interrupt flag, bclif, is set, the start condition is aborted and the i 2 c module is reset into its idle state. note: because queueing of events is not allowed, writing to the lower 5 bits of sspcon2 is disabled until the start condition is complete. sda scl s t brg 1st bit 2nd bit t brg sda = 1 , at completion of start bit, scl = 1 write to sspbuf occurs here t brg hardware clears sen bit t brg write to sen bit occurs here set s bit (sspstat<3>) and sets sspif bit
? 2011 microchip technology inc. ds39977d-page 325 pic18f66k80 family 21.4.9 i 2 c? master mode repeated start condition timing a repeated start condition occurs when the rsen bit (sspcon2<1>) is programmed high and the i 2 c logic module is in the idle state. when the rsen bit is set, the scl pin is asserted low. when the scl pin is sampled low, the baud rate generator is loaded with the contents of sspadd<5:0> and begins counting. the sda pin is released (brought high) for one baud rate generator count (t brg ). when the baud rate generator times out, and if sda is sampled high, the scl pin will be deasserted (brought high). when scl is sampled high, the baud rate generator is reloaded with the contents of sspadd<6:0> and begins counting. sda and scl must be sampled high for one t brg . this action is then followed by assertion of the sda pin (sda = 0 ) for one t brg while scl is high. following this, the rsen bit (sspcon2<1>) will be automatically cleared and the baud rate generator will not be reloaded, leaving the sda pin held low. as soon as a start condition is detected on the sda and scl pins, the s bit (sspstat<3>) will be set. the sspif bit will not be set until the baud rate generator has timed out. immediately following the sspif bit getting set, the user may write the sspbuf with the 7-bit address in 7-bit mode or the default first address in 10-bit mode. after the first eight bits are transmitted and an ack is received, the user may then transmit an additional eight bits of address (10-bit mode) or eight bits of data (7-bit mode). 21.4.9.1 wcol status flag if the user writes the sspbuf when a repeated start sequence is in progress, the wcol is set and the contents of the buffer are unchanged (the write doesn?t occur). figure 21-22: repeated start condition waveform note 1: if rsen is programmed while any other event is in progress, it will not take effect. 2: a bus collision during the repeated start condition occurs if: ? sda is sampled low when scl goes from low-to-high. ? scl goes low before sda is asserted low. this may indicate that another master is attempting to transmit a data ? 1 ?. note: because queueing of events is not allowed, writing of the lower 5 bits of sspcon2 is disabled until the repeated start condition is complete. sda scl sr = repeated start write to sspcon2 write to sspbuf occurs here on falling edge of ninth clock, end of xmit at completion of start bit, hardware clears rsen bit 1st bit s bit set by hardware t brg sda = 1 , sda = 1 , scl (no change). scl = 1 occurs here: and sets sspif rsen bit set by hardware t brg t brg t brg t brg
pic18f66k80 family ds39977d-page 326 ? 2011 microchip technology inc. 21.4.10 i 2 c? master mode transmission transmission of a data byte, a 7-bit address or the other half of a 10-bit address, is accomplished by simply writing a value to the sspbuf register. this action will set the buffer full flag bit, bf, and allow the baud rate generator to begin counting and start the next transmission. each bit of address/data will be shifted out onto the sda pin after the falling edge of scl is asserted (see data hold time specification parameter 106). scl is held low for one baud rate generator rollover count (t brg ). data should be valid before scl is released high (see data setup time spec- ification parameter 107). when the scl pin is released high, it is held that way for t brg . the data on the sda pin must remain stable for that duration and some hold time after the next falling edge of scl. after the eighth bit is shifted out (the falling edge of the eighth clock), the bf flag is cleared and the master releases sda. this allows the slave device being addressed to respond with an ack bit during the ninth bit time if an address match occurred, or if data was received prop- erly. the status of ack is written into the ackdt bit on the falling edge of the ninth clock. if the master receives an acknowledge, the acknowledge status bit, ackstat, is cleared; if not, the bit is set. after the ninth clock, the sspif bit is set and the master clock (baud rate generator) is suspended until the next data byte is loaded into the sspbuf, leaving scl low and sda unchanged ( figure 21-23 ). after the write to the sspbuf, each bit of the address will be shifted out on the falling edge of scl until all seven address bits and the r/w bit are completed. on the falling edge of the eighth clock, the master will deassert the sda pin, allowing the slave to respond with an acknowledge. on the falling edge of the ninth clock, the master will sample the sda pin to see if the address was recognized by a slave. the status of the ack bit is loaded into the ackstat status bit (sspcon2<6>). following the falling edge of the ninth clock transmission of the address, the sspif flag is set, the bf flag is cleared and the baud rate generator is turned off until another write to the sspbuf takes place, holding scl low and allowing sda to float. 21.4.10.1 bf status flag in transmit mode, the bf bit (sspstat<0>) is set when the cpu writes to sspbuf and is cleared when all 8 bits are shifted out. 21.4.10.2 wcol status flag if the user writes the sspbuf when a transmit is already in progress (i.e., sspsr is still shifting out a data byte), the wcol bit is set and the contents of the buffer are unchanged (the write doesn?t occur) after 2t cy after the sspbuf write. if sspbuf is rewritten within 2 t cy , the wcol bit is set and sspbuf is updated. this may result in a corrupted transfer. the user should verify that the wcol bit is clear after each write to sspbuf to ensure the transfer is correct. in all cases, wcol must be cleared in software. 21.4.10.3 ackstat status flag in transmit mode, the ackstat bit (sspcon2<6>) is cleared when the slave has sent an acknowledge (ack = 0 ) and is set when the slave does not acknowl- edge (ack = 1 ). a slave sends an acknowledge when it has recognized its address (including a general call), or when the slave has properly received its data. 21.4.11 i 2 c? master mode reception master mode reception is enabled by programming the receive enable bit, rcen (sspcon2<3>). the baud rate generator begins counting, and on each rollover, the state of the scl pin changes (high-to-low/low-to-high) and data is shifted into the sspsr. after the falling edge of the eighth clock, the receive enable flag is automatically cleared, the con- tents of the sspsr are loaded into the sspbuf, the bf flag bit is set, the sspif flag bit is set and the baud rate generator is suspended from counting, holding scl low. the mssp is now in idle state awaiting the next command. when the buffer is read by the cpu, the bf flag bit is automatically cleared. the user can then send an acknowledge bit at the end of reception by setting the acknowledge sequence enable bit, acken (sspcon2<4>). 21.4.11.1 bf status flag in receive operation, the bf bit is set when an address or data byte is loaded into sspbuf from sspsr. it is cleared when the sspbuf register is read. 21.4.11.2 sspov status flag in receive operation, the sspov bit is set when 8 bits are received into the sspsr and the bf flag bit is already set from a previous reception. 21.4.11.3 wcol status flag if the user writes the sspbuf when a receive is already in progress (i.e., sspsr is still shifting in a data byte), the wcol bit is set and the contents of the buffer are unchanged (the write doesn?t occur). note: the mssp module must be in an inactive state before the rcen bit is set or the rcen bit will be disregarded.
? 2011 microchip technology inc. ds39977d-page 327 pic18f66k80 family figure 21-23: i 2 c? master mode waveform (transmission, 7 or 10-bit address) sda scl sspif bf (sspstat<0>) sen a7 a6 a5 a4 a3 a2 a1 ack = 0 d7 d6 d5 d4 d3 d2 d1 d0 ack transmitting data or second half r/w = 0 transmit address to slave 123456789 123456789 p cleared in software service routine sspbuf is written in software from mssp interrupt after start condition, sen cleared by hardware s sspbuf written with 7-bit address and r/w , start transmit scl held low while cpu responds to sspif sen = 0 of 10-bit address write sspcon2<0> (sen = 1 ), start condition begins from slave, clear ackstat bit (sspcon2<6>) ackstat in sspcon2 = 1 cleared in software sspbuf written pen r/w cleared in software
pic18f66k80 family ds39977d-page 328 ? 2011 microchip technology inc. figure 21-24: i 2 c? master mode waveform (reception, 7-bit address) p 9 8 7 6 5 d0 d1 d2 d3 d4 d5 d6 d7 s a7 a6 a5 a4 a3 a2 a1 sda scl 12 3 4 5 6 7 8 9 12 3 4 5 678 9 1234 bus master terminates transfer ack receiving data from slave receiving data from slave d0 d1 d2 d3 d4 d5 d6 d7 ack r/w = 1 transmit address to slave sspif bf ack is not sent write to sspcon2<0> (sen = 1 ), write to sspbuf occurs here, ack from slave master configured as a receiver by programming sspcon2<3> (rcen = 1 ) pen bit = 1 written here data shifted in on falling edge of clk cleared in software start xmit sen = 0 sspov sda = 0 , scl = 1 , while cpu (sspstat<0>) ack cleared in software cleared in software set sspif interrupt at end of receive set p bit (sspstat<4>) and sspif ack from master, set sspif at end set sspif interrupt at end of acknowledge sequence set sspif interrupt at end of acknowledge sequence of receive set acken, start acknowledge sequence, sda = ackdt = 1 rcen cleared automatically rcen = 1 , start next receive write to sspcon2<4> to start acknowledge sequence, sda = ackdt (sspcon2<5>) = 0 rcen cleared automatically responds to sspif acken begin start condition cleared in software sda = ackdt = 0 last bit is shifted into sspsr and contents are unloaded into sspbuf cleared in software sspov is set because sspbuf is still full
? 2011 microchip technology inc. ds39977d-page 329 pic18f66k80 family 21.4.12 acknowledge sequence timing an acknowledge sequence is enabled by setting the acknowledge sequence enable bit, acken (sspcon2<4>). when this bit is set, the scl pin is pulled low and the contents of the acknowledge data bit are presented on the sda pin. if the user wishes to gen- erate an acknowledge, then the ackdt bit should be cleared. if not, the user should set the ackdt bit before starting an acknowledge sequence. the baud rate gen- erator then counts for one rollover period (t brg ) and the scl pin is deasserted (pulled high). when the scl pin is sampled high (clock arbitration), the baud rate generator counts for t brg ; the scl pin is then pulled low. following this, the acken bit is automatically cleared, the baud rate generator is turned off and the mssp module then goes into an inactive state ( figure 21-25 ). 21.4.12.1 wcol status flag if the user writes the sspbuf when an acknowledge sequence is in progress, then wcol is set and the contents of the buffer are unchanged (the write doesn?t occur). 21.4.13 stop condition timing a stop bit is asserted on the sda pin at the end of a receive/transmit by setting the stop sequence enable bit, pen (sspcon2<2>). at the end of a receive/transmit, the scl line is held low after the falling edge of the ninth clock. when the pen bit is set, the master will assert the sda line low. when the sda line is sampled low, the baud rate generator is reloaded and counts down to 0. when the baud rate generator times out, the scl pin will be brought high and one t brg (baud rate generator rollover count) later, the sda pin will be deasserted. when the sda pin is sampled high while scl is high, the p bit (sspstat<4>) is set. a t brg later, the pen bit is cleared and the sspif bit is set ( figure 21-26 ). 21.4.13.1 wcol status flag if the user writes the sspbuf when a stop sequence is in progress, then the wcol bit is set and the contents of the buffer are unchanged (the write doesn?t occur). figure 21-25: acknowledge sequence waveform figure 21-26: stop condition receive or transmit mode note: t brg = one baud rate generator period. sda scl sspif set at acknowledge sequence starts here, write to sspcon2, acken automatically cleared cleared in t brg t brg the end of receive 8 acken = 1 , ackdt = 0 d0 9 sspif software sspif set at the end of acknowledge sequence cleared in software ack scl sda sda asserted low before rising edge of clock write to sspcon2, set pen falling edge of scl = 1 for t brg , followed by sda = 1 for t brg 9th clock scl brought high after t brg note: t brg = one baud rate generator period. t brg t brg after sda sampled high. p bit (sspstat<4>) is set t brg to set up stop condition ack p t brg pen bit (sspcon2<2>) is cleared by hardware and the sspif bit is set
pic18f66k80 family ds39977d-page 330 ? 2011 microchip technology inc. 21.4.14 sleep operation while in sleep mode, the i 2 c module can receive addresses or data and when an address match or complete byte transfer occurs, wake the processor from sleep (if the mssp interrupt is enabled). 21.4.15 effects of a reset a reset disables the mssp module and terminates the current transfer. 21.4.16 multi-master mode in multi-master mode, the interrupt generation on the detection of the start and stop conditions allows the determination of when the bus is free. the stop (p) and start (s) bits are cleared from a reset or when the mssp module is disabled. control of the i 2 c bus may be taken when the p bit (sspstat<4>) is set, or the bus is idle, with both the s and p bits clear. when the bus is busy, enabling the mssp interrupt will generate the interrupt when the stop condition occurs. in multi-master operation, the sda line must be monitored for arbitration to see if the signal level is the expected output level. this check is performed in hardware with the result placed in the bclif bit. the states where arbitration can be lost are: ? address transfer ? data transfer ? a start condition ? a repeated start condition ? an acknowledge condition 21.4.17 multi -master communication, bus collision and bus arbitration multi-master mode support is achieved by bus arbitra- tion. when the master outputs address/data bits onto the sda pin, arbitration takes place when the master outputs a ? 1 ? on sda, by letting sda float high, and another master asserts a ? 0 ?. when the scl pin floats high, data should be stable. if the expected data on sda is a ? 1 ? and the data sampled on the sda pin = 0 , then a bus collision has taken place. the master will set the bus collision interrupt flag, bclif, and reset the i 2 c port to its idle state ( figure 21-27 ). if a transmit was in progress when the bus collision occurred, the transmission is halted, the bf flag is cleared, the sda and scl lines are deasserted and the sspbuf can be written to. when the user services the bus collision interrupt service routine and if the i 2 c bus is free, the user can resume communication by asserting a start condition. if a start, repeated start, stop or acknowledge condition was in progress when the bus collision occurred, the con- dition is aborted, the sda and scl lines are deasserted and the respective control bits in the sspcon2 register are cleared. when the user services the bus collision interrupt service routine, and if the i 2 c bus is free, the user can resume communication by asserting a start condition. the master will continue to monitor the sda and scl pins. if a stop condition occurs, the sspif bit will be set. a write to the sspbuf will start the transmission of data at the first data bit regardless of where the transmitter left off when the bus collision occurred. in multi-master mode, the interrupt generation on the detection of start and stop conditions allows the determi- nation of when the bus is free. control of the i 2 c bus can be taken when the p bit is set in the sspstat register, or the bus is idle and the s and p bits are cleared. figure 21-27: bus collision timing for transmit and acknowledge sda scl bclif sda released sda line pulled low by another source sample sda. while scl is high, data doesn?t match what is driven bus collision has occurred. set bus collision interrupt (bclif) by the master; by master data changes while scl = 0
? 2011 microchip technology inc. ds39977d-page 331 pic18f66k80 family 21.4.17.1 bus collision during a start condition during a start condition, a bus collision occurs if: a) sda or scl is sampled low at the beginning of the start condition ( figure 21-28 ). b) scl is sampled low before sda is asserted low ( figure 21-29 ). during a start condition, both the sda and the scl pins are monitored. if the sda pin is already low, or the scl pin is already low, then all of the following occur: ? the start condition is aborted, ? the bclif flag is set and ? the mssp module is reset to its inactive state ( figure 21-28 ) the start condition begins with the sda and scl pins deasserted. when the sda pin is sampled high, the baud rate generator is loaded from sspadd<6:0> and counts down to 0. if the scl pin is sampled low while sda is high, a bus collision occurs because it is assumed that another master is attempting to drive a data ? 1 ? during the start condition. if the sda pin is sampled low during this count, the brg is reset and the sda line is asserted early ( figure 21-30 ). if, however, a ? 1 ? is sampled on the sda pin, the sda pin is asserted low at the end of the brg count. the baud rate generator is then reloaded and counts down to 0. if the scl pin is sampled as ? 0 ? during this time, a bus collision does not occur. at the end of the brg count, the scl pin is asserted low. figure 21-28: bus collision during start condition (sda only) note: the reason that bus collision is not a fac- tor during a start condition is that no two bus masters can assert a start condition at the exact same time. therefore, one master will always assert sda before the other. this condition does not cause a bus collision because the two masters must be allowed to arbitrate the first address following the start condition. if the address is the same, arbitration must be allowed to continue into the data portion, repeated start or stop conditions. sda scl sen sda sampled low before sda goes low before the sen bit is set. s bit and sspif set because mssp module reset into idle state. sen cleared automatically because of bus collision. s bit and sspif set because set sen, enable start condition if sda = 1 , scl = 1 sda = 0 , scl = 1 . bclif s sspif sda = 0 , scl = 1 . sspif and bclif are cleared in software sspif and bclif are cleared in software set bclif, start condition. set bclif.
pic18f66k80 family ds39977d-page 332 ? 2011 microchip technology inc. figure 21-29: bus collision during start condition (scl = 0 ) figure 21-30: brg reset due to sda arbitration during start condition sda scl sen bus collision occurs. set bclif. scl = 0 before sda = 0 , set sen, enable start sequence if sda = 1 , scl = 1 t brg t brg sda = 0 , scl = 1 bclif s sspif interrupt cleared in software bus collision occurs. set bclif. scl = 0 before brg time-out, ? 0 ?? 0 ? ? 0 ? ? 0 ? sda scl sen set s less than t brg t brg sda = 0 , scl = 1 bclif s sspif s interrupts cleared in software set sspif sda = 0 , scl = 1 , scl pulled low after brg time-out set sspif ? 0 ? sda pulled low by other master. reset brg and assert sda. set sen, enable start sequence if sda = 1 , scl = 1
? 2011 microchip technology inc. ds39977d-page 333 pic18f66k80 family 21.4.17.2 bus collision during a repeated start condition during a repeated start condition, a bus collision occurs if: a) a low level is sampled on sda when scl goes from a low level to a high level. b) scl goes low before sda is asserted low, indicating that another master is attempting to transmit a data ? 1 ?. when the user deasserts sda and the pin is allowed to float high, the brg is loaded with sspadd<6:0> and counts down to 0. the scl pin is then deasserted and when sampled high, the sda pin is sampled. if sda is low, a bus collision has occurred (i.e., another master is attempting to transmit a data ? 0 ?, figure 21-31 ). if sda is sampled high, the brg is reloaded and begins counting. if sda goes from high-to-low before the brg times out, no bus collision occurs because no two masters can assert sda at exactly the same time. if scl goes from high-to-low before the brg times out and sda has not already been asserted, a bus collision occurs. in this case, another master is attempting to transmit a data ? 1 ? during the repeated start condition (see figure 21-32 ). if, at the end of the brg time-out, both scl and sda are still high, the sda pin is driven low and the brg is reloaded and begins counting. at the end of the count, regardless of the status of the scl pin, the scl pin is driven low and the repeated start condition is complete. figure 21-31: bus collision during a repeated start condition (case 1) figure 21-32: bus collision during repeated start condition (case 2) sda scl rsen bclif s sspif sample sda when scl goes high. if sda = 0 , set bclif and release sda and scl. cleared in software ? 0 ? ? 0 ? sda scl bclif rsen s sspif interrupt cleared in software scl goes low before sda, set bclif. release sda and scl. t brg t brg ? 0 ?
pic18f66k80 family ds39977d-page 334 ? 2011 microchip technology inc. 21.4.17.3 bus collision during a stop condition bus collision occurs during a stop condition if: a) after the sda pin has been deasserted and allowed to float high, sda is sampled low after the brg has timed out. b) after the scl pin is deasserted, scl is sampled low before sda goes high. the stop condition begins with sda asserted low. when sda is sampled low, the scl pin is allowed to float. when the pin is sampled high (clock arbitration), the baud rate generator is loaded with sspadd<6:0> and counts down to 0. after the brg times out, sda is sampled. if sda is sampled low, a bus collision has occurred. this is due to another master attempting to drive a data ? 0 ? ( figure 21-33 ). if the scl pin is sampled low before sda is allowed to float high, a bus collision occurs. this is another case of another master attempting to drive a data ? 0 ? ( figure 21-34 ). figure 21-33: bus collision during a stop condition (case 1) figure 21-34: bus collision during a stop condition (case 2) sda scl bclif pen p sspif t brg t brg t brg sda asserted low sda sampled low after t brg , set bclif ? 0 ? ? 0 ? sda scl bclif pen p sspif t brg t brg t brg assert sda scl goes low before sda goes high, set bclif ? 0 ? ? 0 ?
? 2011 microchip technology inc. ds39977d-page 335 pic18f66k80 family table 21-4: registers associated with i 2 c? operation name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif pir1 pspif adif rc1if tx1if sspif tmr1gif tmr2if tmr1if pie1 pspie adie rc1ie tx1ie sspie tmr1gie tmr2ie tmr1ie ipr1 pspip adip rc1ip tx1ip sspip tmr1gip tmr2ip tmr1ip pir2 oscfif ? ? ?bclif hlvdif tmr3if tmr3gif pie2 oscfie ? ? ?bclie hlvdie tmr3ie tmr3gie ipr2 oscfip ? ? ?bclip hlvdip tmr3ip tmr3gip trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 sspbuf mssp receive buffer/transmit register sspadd mssp address register (i 2 c? slave mode), mssp baud rate reload register (i 2 c master mode) sspmsk (1) msk7 msk6 msk5 msk4 msk3 msk2 msk1 msk0 sspcon1 wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 sspcon2 gcen ackstat ackdt acken rcen pen rsen sen gcen ackstat admsk5 (2) admsk4 (2) admsk3 (2) admsk2 (2) admsk1 (2) sen sspstat smp cke d/a psr/w ua bf pmd0 ccp5md ccp4md ccp3md ccp2md ccp1md uart2md uart1md sspmd odcon sspod ccp5od ccp4od ccp3od ccp2od ccp1od u2od u1od legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the mssp module in i 2 c? mode. note 1: sspmsk shares the same address in sfr space as sspadd, but is only accessible in certain i 2 c? slave operating modes in 7-bit masking mode. see section 21.4.3.4 ?7-bit address masking mode? for more details. 2: alternate bit definitions for use in i 2 c slave mode operations only.
pic18f66k80 family ds39977d-page 336 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds39977d-page 337 pic18f66k80 family 22.0 enhanced universal synchronous asynchronous receiver transmitter (eusart) the enhanced universal synchronous asynchronous receiver transmitter (eusart) module is one of two serial i/o modules. (generically, the eusart is also known as a serial communications interface or sci.) the eusart can be configured as a full-duplex, asynchronous system that can communicate with peripheral devices, such as crt terminals and personal computers. it can also be configured as a half-duplex synchronous system that can communicate with peripheral devices, such as a/d or d/a integrated circuits, serial eeproms, etc. the enhanced usart module implements additional features, including automatic baud rate detection and calibration, automatic wake-up on sync break recep- tion and 12-bit break character transmit. these make it ideally suited for use in local interconnect network bus (lin/j2602 bus) systems. all members of the pic18f66k80 family are equipped with two independent eusart modules, referred to as eusart1 and eusart2. they can be configured in the following modes: ? asynchronous (full duplex) with: - auto-wake-up on character reception - auto-baud calibration - 12-bit break character transmission ? synchronous ? master (half duplex) with selectable clock polarity ? synchronous ? slave (half duplex) with selectable clock polarity the pins of eusart1 and eusart2 are multiplexed with the functions with the following ports, depending on the device pin count. see table 22-1 . in order to configure the pins as an eusart: ? for eusart1: - spen (rcsta1<7>) must be set (= 1 ) - trisx must be set (= 1 ) - for asynchronous and synchronous master modes, trisx must be cleared (= 0 ) - for synchronous slave mode, trisc must be set (= 1 ) ? for eusart2: - spen (rcsta2<7>) must be set (= 1 ) - trisx must be set (= 1 ) - for asynchronous and synchronous master modes, trisx must be cleared (= 0 ) - for synchronous slave mode, trisx must be set (= 1 ) table 22-1: configuring eusart pins (1) pin count usart1 usart2 port pins port pins 28-pin portb rb6/pgc/tx2/ck2/kbi2 and rb7/pgd/t3g/rx2/dt2/kbi3 portc rc6/tx1/ck1 and rc7/rx1/dt1 40/44-pin portc rc6/tx1/ck1 and rc7/rx1/dt1 portd rd6/tx2/ck2/p1c/psp6 and rd7/rx2/dt2/p1d/psp7 64-pin porte re7/tx2/ck2 and re6/rx2/dt2 portg rg3/tx1/ck1 and rg0/rx1/dt1 note 1: the eusart control will automatically reconfigure the pin from input to output as needed.
pic18f66k80 family ds39977d-page 338 ? 2011 microchip technology inc. 22.1 eusart control registers the operation of each enhanced usart module is controlled through three registers: ? transmit status and control (txstax) ? receive status and control (rcstax) ? baud rate control (baudconx) these are detailed on the following pages in register 22-1 , register 22-2 and register 22-3 , respectively. register 22-1: txstax: transmit status and control register note: throughout this section, references to register and bit names that may be asso- ciated with a specific eusart module are referred to generically by the use of ?x? in place of the specific module number. thus, ?rcstax? might refer to the receive status register for either eusart1 or eusart2. r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r-x r/w-x csrc tx9 txen (1) sync sendb brgh trmt tx9d bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 csrc: clock source select bit asynchronous mode: don?t care. synchronous mode: 1 = master mode (clock generated internally from brg) 0 = slave mode (clock from external source) bit 6 tx9: 9-bit transmit enable bit 1 = selects 9-bit transmission 0 = selects 8-bit transmission bit 5 txen: transmit enable bit (1) 1 = transmit is enabled 0 = transmit is disabled bit 4 sync: eusart mode select bit 1 = synchronous mode 0 = asynchronous mode bit 3 sendb: send break character bit asynchronous mode: 1 = send sync break on next transmission (cleared by hardware upon completion) 0 = sync break transmission completed synchronous mode: don?t care. bit 2 brgh: high baud rate select bit asynchronous mode: 1 = high speed 0 = low speed synchronous mode: unused in this mode. bit 1 trmt: transmit shift register status bit 1 = tsr is empty 0 = tsr is full bit 0 tx9d: 9th bit of transmit data can be address/data bit or a parity bit. note 1: sren/cren overrides txen in sync mode.
? 2011 microchip technology inc. ds39977d-page 339 pic18f66k80 family register 22-2: rcstax: receive stat us and control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-0 r-0 r-x spen rx9 sren cren adden ferr oerr rx9d bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 spen: serial port enable bit 1 = serial port is enabled (configures rxx/dtx and txx/ckx pins as serial port pins) 0 = serial port is disabled (held in reset) bit 6 rx9: 9-bit receive enable bit 1 = selects 9-bit reception 0 = selects 8-bit reception bit 5 sren: single receive enable bit asynchronous mode : don?t care. synchronous mode ? master: 1 = enables single receive 0 = disables single receive this bit is cleared after reception is complete. synchronous mode ? slave: don?t care. bit 4 cren: continuous receive enable bit asynchronous mode: 1 = enables receiver 0 = disables receiver synchronous mode: 1 = enables continuous receive until enable bit, cren, is cleared (cren overrides sren) 0 = disables continuous receive bit 3 adden: address detect enable bit asynchronous mode 9-bit (rx9 = 1 ) : 1 = enables address detection, enables interrupt and loads the receive buffer when rsr<8> is set 0 = disables address detection, all bytes are received and the ninth bit can be used as a parity bit asynchronous mode 9-bit (rx9 = 0 ) : don?t care. bit 2 ferr: framing error bit 1 = framing error (can be cleared by reading the rcregx register and receiving next valid byte) 0 = no framing error bit 1 oerr: overrun error bit 1 = overrun error (can be cleared by clearing bit, cren) 0 = no overrun error bit 0 rx9d: 9th bit of received data this can be address/data bit or a parity bit and must be calculated by user firmware.
pic18f66k80 family ds39977d-page 340 ? 2011 microchip technology inc. register 22-3: baudconx: baud rate control register r/w-0 r-1 r/w-x r/w-0 r/w-0 u-0 r/w-0 r/w-0 abdovf rcidl rxdtp txckp brg16 ? wue abden bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 abdovf: auto-baud acquisition rollover status bit 1 = a brg rollover has occurred during auto-baud rate detect mode (must be cleared in software) 0 = no brg rollover has occurred bit 6 rcidl: receive operation idle status bit 1 = receive operation is idle 0 = receive operation is active bit 5 rxdtp: received data polarity select bit (asynchronous mode only) asynchronous mode: 1 = receive data (rxx) is inverted 0 = receive data (rxx) is not inverted bit 4 txckp: clock and data polarity select bit asynchronous mode: 1 = idle state for transmit (txx) is a low level 0 = idle state for transmit (txx) is a high level synchronous mode: 1 = idle state for clock (ckx) is a high level 0 = idle state for clock (ckx) is a low level bit 3 brg16: 16-bit baud rate register enable bit 1 = 16-bit baud rate generator ? spbrghx and spbrgx 0 = 8-bit baud rate generator ? spbrgx only (compatible mode), spbrghx value is ignored bit 2 unimplemented: read as ? 0 ? bit 1 wue: wake-up enable bit asynchronous mode: 1 = eusart will continue to sample the rxx pin: interrupt generated on falling edge; bit cleared in hardware on following rising edge 0 = rxx pin not monitored or rising edge detected synchronous mode: unused in this mode. bit 0 abden: auto-baud detect enable bit asynchronous mode: 1 = enable baud rate measurement on the next character: requires reception of a sync field (55h); cleared in hardware upon completion. 0 = baud rate measurement disabled or completed synchronous mode: unused in this mode.
? 2011 microchip technology inc. ds39977d-page 341 pic18f66k80 family 22.2 baud rate generator (brg) the brg is a dedicated, 8-bit or 16-bit generator that supports both the asynchronous and synchronous modes of the eusart. by default, the brg operates in 8-bit mode; setting the brg16 bit (baudconx<3>) selects 16-bit mode. the spbrghx:spbrgx register pair controls the period of a free-running timer. in asynchronous mode, bits, brgh (txstax<2>) and brg16 (baudconx<3>), also control the baud rate. in synchronous mode, brgh is ignored. table 22-2 shows the formula for computation of the baud rate for different eusart modes which only apply in master mode (internally generated clock). given the desired baud rate and f osc , the nearest integer value for the spbrghx:spbrgx registers can be calculated using the formulas in tab le 2 2- 2 . from this, the error in baud rate can be determined. an example calculation is shown in example 22-1 . typical baud rates and error values for the various asynchronous modes are shown in ta b l e 2 2 - 3 . it may be advantageous to use the high baud rate (brgh = 1 ) or the 16-bit brg to reduce the baud rate error, or achieve a slow baud rate for a fast oscillator frequency. writing a new value to the spbrghx:spbrgx regis- ters causes the brg timer to be reset (or cleared). this ensures the brg does not wait for a timer overflow before outputting the new baud rate. 22.2.1 operation in power-managed modes the device clock is used to generate the desired baud rate. when one of the power-managed modes is entered, the new clock source may be operating at a different frequency. this may require an adjustment to the value in the spbrghx:spbrgx register pair. 22.2.2 sampling the data on the rxx pin (either rc7/canrx/rx1/dt1 or rb7/pgd/t3g/rx2/dt2/kbi3) is sampled three times by a majority detect circuit to determine if a high or a low level is present at the rxx pin. table 22-2: baud rate formulas configuration bits brg/eusart mode baud rate formula sync brg16 brgh 000 8-bit/asynchronous f osc /[64 (n + 1)] 001 8-bit/asynchronous f osc /[16 (n + 1)] 010 16-bit/asynchronous 011 16-bit/asynchronous f osc /[4 (n + 1)] 10x 8-bit/synchronous 11x 16-bit/synchronous legend: x = don?t care, n = value of spbrghx:spbrgx register pair
pic18f66k80 family ds39977d-page 342 ? 2011 microchip technology inc. example 22-1: calculating baud rate error table 22-3: registers associated with baud rate generator name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 txsta1 csrc tx9 txen sync sendb brgh trmt tx9d rcsta1 spen rx9 sren cren adden ferr oerr rx9d baudcon1 abdovf rcidl rxdtp txckp brg16 ? wue abden spbrgh1 eusart1 baud rate generator register high byte spbrg1 eusart1 baud rate generator register txsta2 csrc tx9 txen sync sendb brgh trmt tx9d rcsta2 spen rx9 sren cren adden ferr oerr rx9d baudcon2 abdovf rcidl rxdtp txckp brg16 ? wue abden spbrgh2 eusart2 baud rate generator register high byte spbrg2 eusart2 baud rate generator register low byte pmd0 ccp5md ccp4md ccp3md ccp2md ccp1md uart2md uart1md sspmd legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the brg. for a device with f osc of 16 mhz, desired baud rate of 9600, asynchronous mode, and 8-bit brg: desired baud rate = f osc /(64 ([spbrghx:spbrgx] + 1)) solving for spbrghx:spbrgx: x = ((f osc /desired baud rate)/64) ? 1 = ((16000000/9600)/64) ? 1 = [25.042] = 25 calculated baud rate = 16000000/(64 (25 + 1)) = 9615 error = (calculated baud rate ? de sired baud rate)/desired baud rate = (9615 ? 9600)/9600 = 0.16%
? 2011 microchip technology inc. ds39977d-page 343 pic18f66k80 family table 22-4: baud rates for asynchronous modes baud rate (k) sync = 0 , brgh = 0 , brg16 = 0 f osc = 64.000 mhz f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 ??? ????????? 1.2 ? ? ? ? ? ? 1.221 1.73 255 1.202 0.16 129 2.4 ? ? ? 2.441 1.73 255 2.404 0.16 129 2.404 0.16 64 9.6 9.615 0.16 103 9.615 0.16 64 9.766 1.73 31 9.766 1.73 15 19.2 19.231 0.16 51 19.531 1.73 31 19.531 1.73 15 19.531 1.73 7 57.6 58.824 2.13 16 56.818 -1.36 10 62.500 8.51 4 52.083 -9.58 2 115.2 111.111 -3.55 8 125.000 8.51 4 104.167 -9.58 2 78.125 -32.18 1 baud rate (k) sync = 0 , brgh = 0 , brg16 = 0 f osc = 8.000 mhz f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 ? ? ? 0.300 0.16 207 0.300 -0.16 103 0.300 -0.16 51 1.2 1.201 -0.16 103 1.202 0.16 51 1.201 -0.16 25 1.201 -0.16 12 2.4 2.403 -0.16 51 2.404 0.16 25 2.403 -0.16 12 ? ? ? 9.6 9.615 -0.16 12 8.929 -6.99 6 ? ? ? ? ? ? 19.2 ? ? ? 20.833 8.51 2 ? ? ? ? ? ? 57.6 ? ? ? 62.500 8.51 0 ? ? ? ? ? ? 115.2 ? ? ? 62.500 -45.75 0 ? ? ? ? ? ? baud rate (k) sync = 0 , brgh = 1 , brg16 = 0 f osc = 64.000 mhz f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 ??? ????????? 1.2???????????? 2.4 ? ? ? ? ? ? ? ? ? 2.441 1.73 255 9.6 ? ? ? 9.766 1.73 255 9.615 0.16 129 9.615 0.16 64 19.2 19.417 1.13 207 19.231 0.16 129 19.231 0.16 64 19.531 1.73 31 57.6 59.701 3.65 68 58.140 0.94 42 56.818 -1.36 21 56.818 -1.36 10 115.2 121.212 5.22 34 113.636 -1.36 21 113.636 -1.36 10 125.000 8.51 4 baud rate (k) sync = 0 , brgh = 1 , brg16 = 0 f osc = 8.000 mhz f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 ? ? ? ? ? ? ? ? ? 0.300 -0.16 207 1.2 ? ? ? 1.202 0.16 207 1.201 -0.16 103 1.201 -0.16 51 2.4 2.403 -0.16 207 2.404 0.16 103 2.403 -0.16 51 2.403 -0.16 25 9.6 9.615 -0.16 51 9.615 0.16 25 9.615 -0.16 12 ? ? ? 19.2 19.230 -0.16 25 19.231 0.16 12 ? ? ? ? ? ? 57.6 55.555 3.55 8 62.500 8.51 3 ? ? ? ? ? ? 115.2 ? ? ? 125.000 8.51 1 ? ? ? ? ? ?
pic18f66k80 family ds39977d-page 344 ? 2011 microchip technology inc. baud rate (k) sync = 0 , brgh = 0 , brg16 = 1 f osc = 64.000 mhz f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.00 13332 0.300 0.00 8332 0.300 0.02 4165 0.300 0.02 2082 1.2 1.200 0.00 3332 1.200 0.02 2082 1.200 -0.03 1041 1.200 -0.03 520 2.4 2.400 0.00 1666 2.402 0.06 1040 2.399 -0.03 520 2.404 0.16 259 9.6 9.592 -0.08 416 9.615 0.16 259 9.615 0.16 129 9.615 0.16 64 19.2 19.417 1.13 207 19.231 0.16 129 19.231 0.16 64 19.531 1.73 31 57.6 59.701 3.65 68 58.140 0.94 42 56.818 -1.36 21 56.818 -1.36 10 115.2 121.212 5.22 34 113.636 -1.36 21 113.636 -1.36 10 125.000 8.51 4 baud rate (k) sync = 0 , brgh = 0 , brg16 = 1 f osc = 8.000 mhz f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 -0.04 1665 0.300 0.04 832 0.300 -0.16 415 0.300 -0.16 207 1.2 1.201 -0.16 415 1.202 0.16 207 1.201 -0.16 103 1.201 -0.16 51 2.4 2.403 -0.16 207 2.404 0.16 103 2.403 -0.16 51 2.403 -0.16 25 9.6 9.615 -0.16 51 9.615 0.16 25 9.615 -0.16 12 ? ? ? 19.2 19.230 -0.16 25 19.231 0.16 12 ? ? ? ? ? ? 57.6 55.555 3.55 8 62.500 8.51 3 ? ? ? ? ? ? 115.2 ? ? ? 125.000 8.51 1 ? ? ? ? ? ? baud rate (k) sync = 0 , brgh = 1 , brg16 = 1 or sync = 1 , brg16 = 1 f osc = 64.000 mhz f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.00 53332 0.300 0.00 33332 0.300 0.00 16665 0.300 0.00 8332 1.2 1.200 0.00 13332 1.200 0.00 8332 1.200 0.02 4165 1.200 0.02 2082 2.4 2.400 0.00 6666 2.400 0.02 4165 2.400 0.02 2082 2.402 0.06 1040 9.6 9.598 -0.02 1666 9.606 0.06 1040 9.596 -0.03 520 9.615 0.16 259 19.2 19.208 0.04 832 19.193 -0.03 520 19.231 0.16 259 19.231 0.16 129 57.6 57.348 -0.44 278 57.803 0.35 172 57.471 -0.22 86 58.140 0.94 42 115.2 115.108 -0.08 138 114.943 -0.22 86 116.279 0.94 42 113.636 -1.36 21 baud rate (k) sync = 0 , brgh = 1 , brg16 = 1 or sync = 1 , brg16 = 1 f osc = 8.000 mhz f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 -0.01 6665 0.300 0.01 3332 0.300 -0.04 1665 0.300 -0.04 832 1.2 1.200 -0.04 1665 1.200 0.04 832 1.201 -0.16 415 1.201 -0.16 207 2.4 2.400 -0.04 832 2.404 0.16 415 2.403 -0.16 207 2.403 -0.16 103 9.6 9.615 -0.16 207 9.615 0.16 103 9.615 -0.16 51 9.615 -0.16 25 19.2 19.230 -0.16 103 19.231 0.16 51 19.230 -0.16 25 19.230 -0.16 12 57.6 57.142 0.79 34 58.824 2.12 16 55.555 3.55 8 ? ? ? 115.2 117.647 -2.12 16 111.111 -3.55 8 ? ? ? ? ? ? table 22-4: baud rates for asynchronous modes (continued)
? 2011 microchip technology inc. ds39977d-page 345 pic18f66k80 family 22.2.3 auto-baud rate detect the enhanced usart module supports the automatic detection and calibration of baud rate. this feature is active only in asynchronous mode and while the wue bit is clear. the automatic baud rate measurement sequence ( figure 22-1 ) begins whenever a start bit is received and the abden bit is set. the calculation is self-averaging. in the auto-baud rate detect (abd) mode, the clock to the brg is reversed. rather than the brg clocking the incoming rxx signal, the rxx signal is timing the brg. in abd mode, the internal baud rate generator is used as a counter to time the bit period of the incoming serial byte stream. once the abden bit is set, the state machine will clear the brg and look for a start bit. the auto-baud rate detect must receive a byte with the value, 55h (ascii ?u?, which is also the lin/j2602 bus sync character), in order to calculate the proper bit rate. the measurement is taken over both a low and a high bit time in order to minimize any effects caused by asymmetry of the incom- ing signal. after a start bit, the spbrgx begins counting up, using the preselected clock source on the first rising edge of rxx. after eight bits on the rxx pin or the fifth rising edge, an accumulated value totalling the proper brg period is left in the spbrghx:spbrgx register pair. once the 5th edge is seen (this should correspond to the stop bit), the abden bit is automatically cleared. if a rollover of the brg occurs (an overflow from ffffh to 0000h), the event is trapped by the abdovf status bit (baudconx<7>). it is set in hardware by brg roll- overs and can be set or cleared by the user in software. abd mode remains active after rollover events and the abden bit remains set ( figure 22-2 ). while calibrating the baud rate period, the brg regis- ters are clocked at 1/8th the preconfigured clock rate. the brg clock will be configured by the brg16 and brgh bits. the brg16 bit must be set to use both spbrg1 and spbrgh1 as a 16-bit counter. this allows the user to verify that no carry occurred for 8-bit modes by checking for 00h in the spbrghx register. refer to table 22-5 for counter clock rates to the brg. while the abd sequence takes place, the eusart state machine is held in idle. the rcxif interrupt is set once the fifth rising edge on rxx is detected. the value in the rcregx needs to be read to clear the rcxif interrupt. the contents of rcregx should be discarded. table 22-5: brg counter clock rates 22.2.3.1 abd and eusart transmission since the brg clock is reversed during abd acquisi- tion, the eusart transmitter cannot be used during abd. this means that whenever the abden bit is set, txregx cannot be written to. users should also ensure that abden does not become set during a transmit sequence. failing to do this may result in unpredictable eusart operation. note 1: if the wue bit is set with the abden bit, auto-baud rate detection will occur on the byte following the break character. 2: it is up to the user to determine that the incoming character baud rate is within the range of the selected brg clock source. some combinations of oscillator frequency and eusart baud rates are not possible due to bit error rates. overall system timing and communication baud rates must be taken into consideration when using the auto-baud rate detection feature. 3: to maximize baud rate range, if that feature is used it is recommended that the brg16 bit (baudconx<3>) be set. brg16 brgh brg counter clock 00 f osc /512 01 f osc /128 10 f osc /128 11 f osc /32
pic18f66k80 family ds39977d-page 346 ? 2011 microchip technology inc. figure 22-1: automatic baud rate calculation figure 22-2: brg overflow sequence brg value rxx pin abden bit rcxif bit bit 0 bit 1 (interrupt) read rcregx brg clock start auto-cleared set by user xxxxh 0000h edge #1 bit 2 bit 3 edge #2 bit 4 bit 5 edge #3 bit 6 bit 7 edge #4 001ch note: the abd sequence requires the eusart module to be configured in asynchronous mode and wue = 0 . spbrgx xxxxh 1ch spbrghx xxxxh 00h edge #5 stop bit start bit 0 xxxxh 0000h 0000h ffffh brg clock abden bit rxx pin abdovf bit brg value
? 2011 microchip technology inc. ds39977d-page 347 pic18f66k80 family 22.3 eusart asynchronous mode the asynchronous mode of operation is selected by clearing the sync bit (txstax<4>). in this mode, the eusart uses standard non-return-to-zero (nrz) format (one start bit, eight or nine data bits and one stop bit). the most common data format is 8 bits. an on-chip, dedicated 8-bit/16-bit baud rate generator can be used to derive standard baud rate frequencies from the oscillator. the eusart transmits and receives the lsb first. the eusart?s transmitter and receiver are functionally independent but use the same data format and baud rate. the baud rate generator produces a clock, either x16 or x64 of the bit shift rate, depending on the brgh and brg16 bits (txstax<2> and baudconx<3>). parity is not supported by the hardware but can be implemented in software and stored as the 9th data bit. when operating in asynchronous mode, the eusart module consists of the following important elements: ? baud rate generator ? sampling circuit ? asynchronous transmitter ? asynchronous receiver ? auto-wake-up on sync break character ? 12-bit break character transmit ? auto-baud rate detection 22.3.1 eusart asynchronous transmitter the eusart transmitter block diagram is shown in figure 22-3 . the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer register, txregx. the txregx register is loaded with data in software. the tsr register is not loaded until the stop bit has been transmitted from the previous load. as soon as the stop bit is transmitted, the tsr is loaded with new data from the txregx register (if available). once the txregx register transfers the data to the tsr register (occurs in one t cy ), the txregx register is empty and the txxif flag bit is set. this interrupt can be enabled or disabled by setting or clearing the interrupt enable bit, txxie. txxif will be set regardless of the state of txxie; it cannot be cleared in software. txxif is also not cleared immediately upon loading txregx, but becomes valid in the second instruction cycle following the load instruction. polling txxif immediately following a load of txregx will return invalid results. while txxif indicates the status of the txregx regis- ter; another bit, trmt (txstax<1>), shows the status of the tsr register. trmt is a read-only bit which is set when the tsr register is empty. no interrupt logic is tied to this bit so the user has to poll this bit in order to determine if the tsr register is empty. to set up an asynchronous transmission: 1. initialize the spbrghx:spbrgx registers for the appropriate baud rate. set or clear the brgh and brg16 bits, as required, to achieve the desired baud rate. 2. enable the asynchronous serial port by clearing bit, sync, and setting bit, spen. 3. if interrupts are desired, set enable bit, txxie. 4. if 9-bit transmission is desired, set transmit bit, tx9. can be used as address/data bit. 5. enable the transmission by setting bit, txen, which will also set bit, txxif. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit, tx9d. 7. load data to the txregx register (starts transmission). 8. if using interrupts, ensure that the gie and peie bits (intcon<7:6>) are set. figure 22-3: eusart transmit block diagram note 1: the tsr register is not mapped in data memory, so it is not available to the user. 2: flag bit, txxif, is set when enable bit, txen, is set. txxif txxie interrupt txen baud rate clk spbrgx baud rate generator tx9d msb lsb data bus txregx register tsr register (8) 0 tx9 trmt spen txx pin pin buffer and control 8 ????????? spbrghx brg16
pic18f66k80 family ds39977d-page 348 ? 2011 microchip technology inc. figure 22-4: asynchronous transmission figure 22-5: asynchronous transmission (back-to-back) word 1 word 1 transmit shift reg start bit bit 0 bit 1 bit 7/8 write to txregx brg output (shift clock) txx (pin) txxif bit (transmit buffer reg. empty flag) trmt bit (transmit shift reg. empty flag) 1 t cy stop bit word 1 transmit shift reg. write to txregx brg output (shift clock) txx (pin) txxif bit (interrupt reg. flag) trmt bit (transmit shift reg. empty flag) word 1 word 2 word 1 word 2 stop bit start bit transmit shift reg. word 1 word 2 bit 0 bit 1 bit 7/8 bit 0 note: this timing diagram shows two consecutive transmissions. 1 t cy 1 t cy start bit
? 2011 microchip technology inc. ds39977d-page 349 pic18f66k80 family table 22-6: registers associated wi th asynchronous transmission name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif pir1 pspif adif rc1if tx1if sspif tmr1gif tmr2if tmr1if pie1 pspie adie rc1ie tx1ie sspie tmr1gie tmr2ie tmr1ie ipr1 pspip adip rc1ip tx1ip sspip tmr1gip tmr2ip tmr1ip pir3 ? ? rc2if tx2if ctmuif ccp2if ccp1if ? pie3 ? ? rc2ie tx2ie ctmuie ccp2ie ccp1ie ? ipr3 ? ? rc2ip tx2ip ctmuip ccp2ip ccp1ip ? rcsta1 spen rx9 sren cren adden ferr oerr rx9d txreg1 eusart1 transmit register txsta1 csrc tx9 txen sync sendb brgh trmt tx9d baudcon1 abdovf rcidl rxdtp txckp brg16 ? wue abden spbrgh1 eusart1 baud rate generator register high byte spbrg1 eusart1 baud rate generator register low byte rcsta2 spen rx9 sren cren adden ferr oerr rx9d txreg2 eusart2 transmit register txsta2 csrc tx9 txen sync sendb brgh trmt tx9d baudcon2 abdovf rcidl rxdtp txckp brg16 ? wue abden spbrgh2 eusart2 baud rate generator register high byte spbrg2 eusart2 baud rate generator register low byte pmd0 ccp5md ccp4md ccp3md ccp2md ccp1md uart2md uart1md sspmd odcon sspod ccp5od ccp4od ccp3od ccp2od ccp1od u2od u1od legend: ? = unimplemented locations read as ? 0 ?. shaded cells are not used for asynchronous transmission.
pic18f66k80 family ds39977d-page 350 ? 2011 microchip technology inc. 22.3.2 eusart asynchronous receiver the receiver block diagram is shown in figure 22-6 . the data is received on the rxx pin and drives the data recovery block. the data recovery block is actually a high-speed shifter operating at x16 times the baud rate, whereas the main receive serial shifter operates at the bit rate or at f osc . this mode would typically be used in rs-232 systems. to set up an asynchronous reception: 1. initialize the spbrghx:spbrgx registers for the appropriate baud rate. set or clear the brgh and brg16 bits, as required, to achieve the desired baud rate. 2. enable the asynchronous serial port by clearing bit, sync, and setting bit, spen. 3. if interrupts are desired, set enable bit, rcxie. 4. if 9-bit reception is desired, set bit, rx9. 5. enable the reception by setting bit, cren. 6. flag bit, rcxif, will be set when reception is complete and an interrupt will be generated if enable bit, rcxie, was set. 7. read the rcstax register to get the 9th bit (if enabled) and determine if any error occurred during reception. 8. read the 8-bit received data by reading the rcregx register. 9. if any error occurred, clear the error by clearing enable bit, cren. 10. if using interrupts, ensure that the gie and peie bits (intcon<7:6>) are set. 22.3.3 setting up 9-bit mode with address detect this mode would typically be used in rs-485 systems. to set up an asynchronous reception with address detect enable: 1. initialize the spbrghx:spbrgx registers for the appropriate baud rate. set or clear the brgh and brg16 bits, as required, to achieve the desired baud rate. 2. enable the asynchronous serial port by clearing the sync bit and setting the spen bit. 3. if interrupts are required, set the rcen bit and select the desired priority level with the rcxip bit. 4. set the rx9 bit to enable 9-bit reception. 5. set the adden bit to enable address detect. 6. enable reception by setting the cren bit. 7. the rcxif bit will be set when reception is complete. the interrupt will be acknowledged if the rcxie and gie bits are set. 8. read the rcstax register to determine if any error occurred during reception, as well as read bit 9 of data (if applicable). 9. read rcregx to determine if the device is being addressed. 10. if any error occurred, clear the cren bit. 11. if the device has been addressed, clear the adden bit to allow all received data into the receive buffer and interrupt the cpu. figure 22-6: eusart receive block diagram x64 baud rate clk baud rate generator rxx pin buffer and control spen data recovery cren oerr ferr rsr register msb lsb rx9d rcregx register fifo interrupt rcxif rcxie data bus 8 ? 64 ? 16 or stop start (8) 7 1 0 rx9 ??????? spbrgx spbrghx brg16 or ? 4
? 2011 microchip technology inc. ds39977d-page 351 pic18f66k80 family figure 22-7: asynchronous reception table 22-7: registers associated with asynchronous reception name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif pir1 pspif adif rc1if tx1if sspif tmr1gif tmr2if tmr1if pie1 pspie adie rc1ie tx1ie sspie tmr1gie tmr2ie tmr1ie ipr1 pspip adip rc1ip tx1ip sspip tmr1gip tmr2ip tmr1ip pir3 ? ? rc2if tx2if ctmuif ccp2if ccp1if ? pie3 ? ? rc2ie tx2ie ctmuie ccp2ie ccp1ie ? ipr3 ? ? rc2ip tx2ip ctmuip ccp2ip ccp1ip ? rcsta1 spen rx9 sren cren adden ferr oerr rx9d rcreg1 eusart1 receive register txsta1 csrc tx9 txen sync sendb brgh trmt tx9d baudcon1 abdovf rcidl rxdtp txckp brg16 ? wue abden spbrgh1 eusart1 baud rate generator register high byte spbrg1 eusart1 baud rate generator register rcsta2 spen rx9 sren cren adden ferr oerr rx9d rcreg2 eusart2 receive register txsta2 csrc tx9 txen sync sendb brgh trmt tx9d baudcon2 abdovf rcidl rxdtp txckp brg16 ? wue abden spbrgh2 eusart2 baud rate generator register high byte spbrg2 eusart2 baud rate generator register low byte pmd0 ccp5md ccp4md ccp3md ccp2md ccp1md uart2md uart1md sspmd odcon sspod ccp5od ccp4od ccp3od ccp2od ccp1od u2od u1od legend: ? = unimplemented locations read as ? 0 ?. shaded cells are not used for asynchronous reception. start bit bit 7/8 bit 1 bit 0 bit 7/8 bit 0 stop bit start bit start bit bit 7/8 stop bit rxx (pin) rcv buffer reg rcv shift reg read rcv buffer reg rcregx rcxif (interrupt flag) oerr bit cren word 1 rcregx word 2 rcregx stop bit note: this timing diagram shows three words appearing on the rxx input. the rcregx (receive buffer) is read after the third word causing the oerr (overrun) bit to be set.
pic18f66k80 family ds39977d-page 352 ? 2011 microchip technology inc. 22.3.4 auto-wake-up on sync break character during sleep mode, all clocks to the eusart are suspended. because of this, the baud rate generator is inactive and a proper byte reception cannot be per- formed. the auto-wake-up feature allows the controller to wake-up due to activity on the rxx/dtx line while the eusart is operating in asynchronous mode. the auto-wake-up feature is enabled by setting the wue bit (baudconx<1>). once set, the typical receive sequence on rxx/dtx is disabled and the eusart remains in an idle state, monitoring for a wake-up event independent of the cpu mode. a wake-up event consists of a high-to-low transition on the rxx/dtx line. (this coincides with the start of a sync break or a wake-up signal character for the lin/j2602 protocol.) following a wake-up event, the module generates an rcxif interrupt. the interrupt is generated synchro- nously to the q clocks in normal operating modes ( figure 22-8 ) and asynchronously if the device is in sleep mode ( figure 22-9 ). the interrupt condition is cleared by reading the rcregx register. the wue bit is automatically cleared once a low-to-high transition is observed on the rxx line following the wake-up event. at this point, the eusart module is in idle mode and returns to normal operation. this signals to the user that the sync break event is over. 22.3.4.1 special considerations using auto-wake-up since auto-wake-up functions by sensing rising edge transitions on rxx/dtx, information with any state changes before the stop bit may signal a false end-of-character (eoc) and cause data or framing errors. to work properly, therefore, the initial character in the transmission must be all ? 0 ?s. this can be 00h (8 bytes) for standard rs-232 devices or 000h (12 bits) for lin/j2602 bus. oscillator start-up time must also be considered, especially in applications using oscillators with longer start-up intervals (i.e., hs or hspll mode). the sync break (or wake-up signal) character must be of sufficient length and be followed by a sufficient interval to allow enough time for the selected oscillator to start and provide proper initialization of the eusart.
? 2011 microchip technology inc. ds39977d-page 353 pic18f66k80 family 22.3.4.2 special considerations using the wue bit the timing of wue and rcxif events may cause some confusion when it comes to determining the validity of received data. as noted, setting the wue bit places the eusart in an idle mode. the wake-up event causes a receive interrupt by setting the rcxif bit. the wue bit is cleared after this when a rising edge is seen on rxx/dtx. the interrupt condition is then cleared by reading the rcregx register. ordinarily, the data in rcregx will be dummy data and should be discarded. the fact that the wue bit has been cleared (or is still set) and the rcxif flag is set should not be used as an indicator of the integrity of the data in rcregx. users should consider implementing a parallel method in firmware to verify received data integrity. to assure that no actual data is lost, check the rcidl bit to verify that a receive operation is not in process. if a receive operation is not occurring, the wue bit may then be set just prior to entering the sleep mode. figure 22-8: auto-wake-up bit (wue) timings during normal operation figure 22-9: auto-wake-up bit (wue) timings during sleep q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 wue bit (1) rxx/dtx line rcxif note 1: the eusart remains in idle while the wue bit is set. bit set by user cleared due to user read of rcregx auto-cleared q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 wue bit (2) rxx/dtx line rcxif cleared due to user read of rcregx sleep command executed note 1: if the wake-up event requires long oscillator warm-up time, the auto-clear of the wue bit can occur before the oscillator is re ady. this sequence should not depend on the presence of q clocks. 2: the eusart remains in idle while the wue bit is set. sleep ends note 1 auto-cleared bit set by user
pic18f66k80 family ds39977d-page 354 ? 2011 microchip technology inc. 22.3.5 break character sequence the eusart module has the capability of sending the special break character sequences that are required by the lin/j2602 bus standard. the break character transmit consists of a start bit, followed by twelve ? 0 ? bits and a stop bit. the frame break character is sent whenever the sendb and txen bits (txstax<3> and txstax<5>, respectively) are set while the transmit shift register is loaded with data. note that the value of data written to txregx will be ignored and all ? 0 ?s will be transmitted. the sendb bit is automatically reset by hardware after the corresponding stop bit is sent. this allows the user to preload the transmit fifo with the next transmit byte following the break character (typically, the sync character in the lin/j2602 specification). note that the data value written to the txregx for the break character is ignored. the write simply serves the purpose of initiating the proper sequence. the trmt bit indicates when the transmit operation is active or idle, just as it does during normal transmis- sion. see figure 22-10 for the timing of the break character sequence. 22.3.5.1 break and sync transmit sequence the following sequence will send a message frame header made up of a break, followed by an auto-baud sync byte. this sequence is typical of a lin/j2602 bus master. 1. configure the eusart for the desired mode. 2. set the txen and sendb bits to set up the break character. 3. load the txregx with a dummy character to initiate transmission (the value is ignored). 4. write ?55h? to txregx to load the sync character into the transmit fifo buffer. 5. after the break has been sent, the sendb bit is reset by hardware. the sync character now transmits in the preconfigured mode. when the txregx becomes empty, as indicated by the txxif, the next data byte can be written to txregx. 22.3.6 receiving a break character the enhanced usart module can receive a break character in two ways. the first method forces configuration of the baud rate at a frequency of 9/13 the typical speed. this allows for the stop bit transition to be at the correct sampling location (13 bits for break versus start bit and 8 data bits for typical data). the second method uses the auto-wake-up feature described in section 22.3.4 ?auto-wake-up on sync break character? . by enabling this feature, the eusart will sample the next two transitions on rxx/dtx, cause an rcxif interrupt and receive the next data byte followed by another interrupt. note that following a break character, the user will typically want to enable the auto-baud rate detect feature. for both methods, the user can set the abden bit once the txxif interrupt is observed. figure 22-10: send break character sequence write to txregx brg output (shift clock) start bit bit 0 bit 1 bit 11 stop bit break txxif bit (transmit buffer reg. empty flag) txx (pin) trmt bit (transmit shift reg. empty flag) sendb bit (transmit shift reg. empty flag) sendb sampled here auto-cleared dummy write
? 2011 microchip technology inc. ds39977d-page 355 pic18f66k80 family 22.4 eusart synchronous master mode the synchronous master mode is entered by setting the csrc bit (txstax<7>). in this mode, the data is transmitted in a half-duplex manner (i.e., transmission and reception do not occur at the same time). when transmitting data, the reception is inhibited and vice versa. synchronous mode is entered by setting bit, sync (txstax<4>). in addition, enable bit, spen (rcstax<7>), is set in order to configure the txx and rxx pins to ckx (clock) and dtx (data) lines, respectively. the master mode indicates that the processor trans- mits the master clock on the ckx line. clock polarity is selected with the txckp bit (baudconx<4>). setting txckp sets the idle state on ckx as high, while clear- ing the bit sets the idle state as low. this option is provided to support microwire devices with this module. 22.4.1 eusart synchronous master transmission the eusart transmitter block diagram is shown in figure 22-3 . the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer register, txregx. the txregx register is loaded with data in software. the tsr register is not loaded until the last bit has been transmitted from the previous load. as soon as the last bit is transmitted, the tsr is loaded with new data from the txregx (if available). once the txregx register transfers the data to the tsr register (occurs in one t cy ), the txregx is empty and the txxif flag bit is set. the interrupt can be enabled or disabled by setting or clearing the interrupt enable bit, txxie. txxif is set regardless of the state of enable bit, txxie; it cannot be cleared in software. it will reset only when new data is loaded into the txregx register. while flag bit, txxif, indicates the status of the txregx register, another bit, trmt (txstax<1>), shows the status of the tsr register. trmt is a read-only bit which is set when the tsr is empty. no interrupt logic is tied to this bit, so the user must poll this bit in order to determine if the tsr register is empty. the tsr is not mapped in data memory so it is not available to the user. to set up a synchronous master transmission: 1. initialize the spbrghx:spbrgx registers for the appropriate baud rate. set or clear the brg16 bit, as required, to achieve the desired baud rate. 2. enable the synchronous master serial port by setting bits, sync, spen and csrc. 3. if interrupts are desired, set enable bit, txxie. 4. if 9-bit transmission is desired, set bit, tx9. 5. enable the transmission by setting bit, txen. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit, tx9d. 7. start transmission by loading data to the txregx register. 8. if using interrupts, ensure that the gie and peie bits (intcon<7:6>) are set. figure 22-11: synchronous transmission bit 0 bit 1 bit 7 word 1 q1 q2 q3q4 q1 q2 q3 q4 q1 q2 q3 q4 q1q2 q3 q4 q1 q2 q3 q4 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 bit 2 bit 0 bit 1 bit 7 dt1/ccp4pin rc6/cantx/tx1/ck1/ write to txreg1 reg tx1if bit (interrupt flag) txen bit ? 1 ? ? 1 ? word 2 trmt bit write word 1 write word 2 note: sync master mode, spbrgx = 0 ; continuous transmission of two 8-bit words. this example is equally applicable to eusart2 (rb6/pgc/tx2/ck2/kbi2 and rb7/pgd/t3g/rx2/dt2/kbi3). rc7/canrx/rx1/ ccp3/pin (txckp = 0 ) rc6/cantx/tx1/ck1/ ccp3/pin (txckp = 1 )
pic18f66k80 family ds39977d-page 356 ? 2011 microchip technology inc. figure 22-12: synchronous transmission (through txen) table 22-8: registers associated with synchronous master transmission name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif pir1 pspif adif rc1if tx1if sspif tmr1gif tmr2if tmr1if pie1 pspie adie rc1ie tx1ie sspie tmr1gie tmr2ie tmr1ie ipr1 pspip adip rc1ip tx1ip sspip tmr1gip tmr2ip tmr1ip pir3 ? ? rc2if tx2if ctmuif ccp2if ccp1if ? pie3 ? ? rc2ie tx2ie ctmuie ccp2ie ccp1ie ? ipr3 ? ? rc2ip tx2ip ctmuip ccp2ip ccp1ip ? rcsta1 spen rx9 sren cren adden ferr oerr rx9d txreg1 eusart1 transmit register txsta1 csrc tx9 txen sync sendb brgh trmt tx9d baudcon1 abdovf rcidl rxdtp txckp brg16 ? wue abden spbrgh1 eusart1 baud rate generator register high byte spbrg1 eusart1 baud rate generator register low byte rcsta2 spen rx9 sren cren adden ferr oerr rx9d txreg2 eusart2 transmit register txsta2 csrc tx9 txen sync sendb brgh trmt tx9d baudcon2 abdovf rcidl rxdtp txckp brg16 ? wue abden spbrgh2 eusart2 baud rate generator register high byte spbrg2 eusart2 baud rate generator register low byte pmd0 ccp5md ccp4md ccp3md ccp2md ccp1md uart2md uart1md sspmd odcon sspod ccp5od ccp4od ccp3od ccp2od ccp1od u2od u1od legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous master transmission. rc7/canrx/rx1/dt1/ rc6/cantx/tx1/ck1/ write to txreg1 reg tx1if bit trmt bit bit 0 bit 1 bit 2 bit 6 bit 7 txen bit note: this example is equally applicable to eusart2 (rb6/pgc/tx2/ck2/kbi2 and rb7/pgd/t3g/rx2/dt2/kbi3). ccp4 pin ccp3 pin
? 2011 microchip technology inc. ds39977d-page 357 pic18f66k80 family 22.4.2 eusart synchronous master reception once synchronous mode is selected, reception is enabled by setting either the single receive enable bit, sren (rcstax<5>) or the continuous receive enable bit, cren (rcstax<4>). data is sampled on the rxx pin on the falling edge of the clock. if enable bit, sren, is set, only a single word is received. if enable bit, cren, is set, the reception is continuous until cren is cleared. if both bits are set, then cren takes precedence. to set up a synchronous master reception: 1. initialize the spbrghx:spbrgx registers for the appropriate baud rate. set or clear the brg16 bit, as required, to achieve the desired baud rate. 2. enable the synchronous master serial port by setting bits, sync, spen and csrc. 3. ensure bits, cren and sren, are clear. 4. if interrupts are desired, set enable bit, rcxie. 5. if 9-bit reception is desired, set bit, rx9. 6. if a single reception is required, set bit, sren. for continuous reception, set bit, cren. 7. interrupt flag bit, rcxif, will be set when recep- tion is complete and an interrupt will be generated if the enable bit, rcxie, was set. 8. read the rcstax register to get the 9th bit (if enabled) and determine if any error occurred during reception. 9. read the 8-bit received data by reading the rcregx register. 10. if any error occurred, clear the error by clearing bit, cren. 11. if using interrupts, ensure that the gie and peie bits (intcon<7:6>) are set. figure 22-13: synchronous reception (master mode, sren) cren bit write to bit, sren sren bit rc1if bit (interrupt) read rcreg1 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q2 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 ? 0 ? bit 0 bit 1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7 ? 0 ? q1 q2 q3 q4 note: timing diagram demonstrates sync master mode with bit, sren = 1, and bit, brgh = 0 . this example is equally applicable to eusart2 (rb6/pgc/tx2/ck2/kbi2 and rb7/pgd/t3g/rx2/dt2/kbi3). rx1/dt1/ccp4 rc7/canrx/ rc6/cantx/tx1/ ck1/ccp3 (txckp = 0 ) rc6/cantx/tx1/ ck1/ccp3 (txckp = 0 )
pic18f66k80 family ds39977d-page 358 ? 2011 microchip technology inc. table 22-9: registers associated with synchronous master reception name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif pir1 pspif adif rc1if tx1if sspif tmr1gif tmr2if tmr1if pie1 pspie adie rc1ie tx1ie sspie tmr1gie tmr2ie tmr1ie ipr1 pspip adip rc1ip tx1ip sspip tmr1gip tmr2ip tmr1ip pir3 ? ? rc2if tx2if ctmuif ccp2if ccp1if ? pie3 ? ? rc2ie tx2ie ctmuie ccp2ie ccp1ie ? ipr3 ? ? rc2ip tx2ip ctmuip ccp2ip ccp1ip ? rcsta1 spen rx9 sren cren adden ferr oerr rx9d rcreg1 eusart1 receive register txsta1 csrc tx9 txen sync sendb brgh trmt tx9d baudcon1 abdovf rcidl rxdtp txckp brg16 ? wue abden spbrgh1 eusart1 baud rate generator register high byte spbrg1 eusart1 baud rate generator register low byte rcsta2 spen rx9 sren cren adden ferr oerr rx9d rcreg2 eusart2 receive register txsta2 csrc tx9 txen sync sendb brgh trmt tx9d baudcon2 abdovf rcidl rxdtp txckp brg16 ? wue abden spbrgh2 eusart2 baud rate generator register high byte spbrg2 eusart2 baud rate generator register low byte pmd0 ccp5md ccp4md ccp3md ccp2md ccp1md uart2md uart1md sspmd odcon sspod ccp5od ccp4od ccp3od ccp2od ccp1od u2od u1od legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous master reception.
? 2011 microchip technology inc. ds39977d-page 359 pic18f66k80 family 22.5 eusart synchronous slave mode synchronous slave mode is entered by clearing bit, csrc (txstax<7>). this mode differs from the synchronous master mode in that the shift clock is sup- plied externally at the ckx pin (instead of being supplied internally in master mode). this allows the device to transfer or receive data while in any low-power mode. 22.5.1 eusart synchronous slave transmission the operation of the synchronous master and slave modes is identical, except in the case of sleep mode. if two words are written to the txregx and then the sleep instruction is executed, the following will occur: a) the first word will immediately transfer to the tsr register and transmit. b) the second word will remain in the txregx register. c) flag bit, txxif, will not be set. d) when the first word has been shifted out of tsr, the txregx register will transfer the second word to the tsr and flag bit, txxif, will now be set. e) if enable bit, txxie, is set, the interrupt will wake the chip from sleep. if the global interrupt is enabled, the program will branch to the interrupt vector. to set up a synchronous slave transmission: 1. enable the synchronous slave serial port by setting bits, sync and spen, and clearing bit, csrc. 2. clear bits, cren and sren. 3. if interrupts are desired, set enable bit, txxie. 4. if 9-bit transmission is desired, set bit, tx9. 5. enable the transmission by setting enable bit, txen. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit, tx9d. 7. start transmission by loading data to the txregx register. 8. if using interrupts, ensure that the gie and peie bits (intcon<7:6>) are set. table 22-10: registers associated with synchronous slave transmission name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif pir1 pspif adif rc1if tx1if sspif tmr1gif tmr2if tmr1if pie1 pspie adie rc1ie tx1ie sspie tmr1gie tmr2ie tmr1ie ipr1 pspip adip rc1ip tx1ip sspip tmr1gip tmr2ip tmr1ip pir3 ? ? rc2if tx2if ctmuif ccp2if ccp1if ? pie3 ? ? rc2ie tx2ie ctmuie ccp2ie ccp1ie ? ipr3 ? ? rc2ip tx2ip ctmuip ccp2ip ccp1ip ? rcsta1 spen rx9 sren cren adden ferr oerr rx9d txreg1 eusart1 transmit register txsta1 csrc tx9 txen sync sendb brgh trmt tx9d baudcon1 abdovf rcidl rxdtp txckp brg16 ? wue abden spbrgh1 eusart1 baud rate generator register high byte spbrg1 eusart1 baud rate generator register low byte rcsta2 spen rx9 sren cren adden ferr oerr rx9d txreg2 eusart2 transmit register txsta2 csrc tx9 txen sync sendb brgh trmt tx9d baudcon2 abdovf rcidl rxdtp txckp brg16 ? wue abden spbrgh2 eusart2 baud rate generator register high byte spbrg2 eusart2 baud rate generator register low byte pmd0 ccp5md ccp4md ccp3md ccp2md ccp1md uart2md uart1md sspmd odcon sspod ccp5od ccp4od ccp3od ccp2od ccp1od u2od u1od legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous slave transmission.
pic18f66k80 family ds39977d-page 360 ? 2011 microchip technology inc. 22.5.2 eusart synchronous slave reception the operation of the synchronous master and slave modes is identical, except in the case of sleep, or any idle mode and bit, sren, which is a ?don?t care? in slave mode. if receive is enabled by setting the cren bit prior to entering sleep or any idle mode, then a word may be received while in this low-power mode. once the word is received, the rsr register will transfer the data to the rcregx register. if the rcxie enable bit is set, the interrupt generated will wake the chip from the low-power mode. if the global interrupt is enabled, the program will branch to the interrupt vector. to set up a synchronous slave reception: 1. enable the synchronous master serial port by setting bits, sync and spen, and clearing bit, csrc. 2. if interrupts are desired, set enable bit, rcxie. 3. if 9-bit reception is desired, set bit, rx9. 4. to enable reception, set enable bit, cren. 5. flag bit, rcxif, will be set when reception is complete. an interrupt will be generated if enable bit, rcxie, was set. 6. read the rcstax register to get the 9th bit (if enabled) and determine if any error occurred during reception. 7. read the 8-bit received data by reading the rcregx register. 8. if any error occurred, clear the error by clearing bit, cren. 9. if using interrupts, ensure that the gie and peie bits (intcon<7:6>) are set. table 22-11: registers associated wi th synchronous slave reception name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif pir1 pspif adif rc1if tx1if sspif tmr1gif tmr2if tmr1if pie1 pspie adie rc1ie tx1ie sspie tmr1gie tmr2ie tmr1ie ipr1 pspip adip rc1ip tx1ip sspip tmr1gip tmr2ip tmr1ip pir3 ? ? rc2if tx2if ctmuif ccp2if ccp1if ? pie3 ? ? rc2ie tx2ie ctmuie ccp2ie ccp1ie ? ipr3 ? ? rc2ip tx2ip ctmuip ccp2ip ccp1ip ? rcsta1 spen rx9 sren cren adden ferr oerr rx9d rcreg1 eusart1 receive register txsta1 csrc tx9 txen sync sendb brgh trmt tx9d baudcon1 abdovf rcidl rxdtp txckp brg16 ? wue abden spbrgh1 eusart1 baud rate generator register high byte spbrg1 eusart1 baud rate generator register low byte rcsta2 spen rx9 sren cren adden ferr oerr rx9d rcreg2 eusart2 receive register txsta2 csrc tx9 txen sync sendb brgh trmt tx9d baudcon2 abdovf rcidl rxdtp txckp brg16 ? wue abden spbrgh2 eusart2 baud rate generator register high byte spbrg2 eusart2 baud rate generator register low byte pmd0 ccp5md ccp4md ccp3md ccp2md ccp1md uart2md uart1md sspmd odcon sspod ccp5od ccp4od ccp3od ccp2od ccp1od u2od u1od legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous slave reception.
? 2011 microchip technology inc. ds39977d-page 361 pic18f66k80 family 23.0 12-bit analog-to-digital converter (a/d) module the analog-to-digital (a/d) converter module in the pic18f66k80 family of devices has eight inputs for the 28-pin devices, 11 inputs for the 40/44-pin and 64-pin devices. this module allows conversion of an analog input signal to a corresponding 12-bit digital number. the module has these registers: ? a/d control register 0 (adcon0) ? a/d control register 1 (adcon1) ? a/d control register 2 (adcon2) ? a/d port configuration register 1 (ancon0) ? a/d port configuration register 2 (ancon1) ? adresh (the upper, a/d results register) ? adresl (the lower, a/d results register) the adcon0 register, shown in register 23-1 , con- trols the operation of the a/d module. the adcon1 register, shown in register 23-2 , configures the voltage reference and special trigger selection. the adcon2 register, shown in register 23-3 , configures the a/d clock source and programmed acquisition time and justification. 23.1 differential a/d converter the converter in pic18f66k80 family devices is implemented as a differential a/d where the differential voltage between two channels is measured and converted to digital values (see figure 23-1 ). the converter also can be configured to measure a voltage from a single input by clearing the chsn bits (adcon1<2:0>). with this configuration, the negative channel input is connected internally to av ss (see figure 23-2 ). figure 23-1: differential channel measurement differential conversion feeds the two input channels to a unity gain differential amplifier. the positive channel input is selected using the chs bits (adcon0<6:2>) and the negative channel input is selected using the chsn bits (adcon1<2:0>). the output from the amplifier is fed to the a/d con- verter, as shown in figure 23-1 . the 12-bit result is available on the adresh and adresl registers. an additional bit indicates if the 12-bit result is a positive or negative value. figure 23-2: single channel measurement in the single channel measurement mode, the negative input is connected to a vss by clearing the chsn bits (adcon1<2:0>). adc positive input chs<4:0> negative input chsn<2:0> + ? adc positive input chs<4:0> chsn<2:0> = 000 + ? av ss
pic18f66k80 family ds39977d-page 362 ? 2011 microchip technology inc. 23.2 a/d registers 23.2.1 a/d control registers register 23-1: adcon0: a/ d control register 0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? chs4 chs3 chs2 chs1 chs0 go/done adon bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-2 chs<4:0>: analog channel select bits 00000 = channel 00 (an0) 10000 =(reserved) (2) 00001 = channel 01 (an1) 10001 =(reserved) (2) 00010 = channel 02 (an2) 10010 =(reserved) (2) 00011 = channel 03 (an3) 10011 =(reserved) (2) 00100 = channel 04 (an4) 10100 =(reserved) (2) 00101 = channel 05 (an5) (1,2) 10101 =(reserved) (2) 00110 = channel 06 (an6) (1,2) 10110 =(reserved) (2) 00111 = channel 07 (an7) (1,2) 10111 =(reserved) (2) 01000 = channel 08 (an8) 11000 =(reserved) (2) 01001 = channel 09 (an9) 11001 =(reserved) (2) 01010 = channel 10 (an10) 11010 =(reserved) (2) 01011 =(reserved) (2) 11011 =(reserved) (2) 01100 =(reserved) (2)) 11100 = (mux disconnect) (3) 01101 =(reserved) (2)) 11101 = channel 29 (temperature diode) 01110 =(reserved) (2)) 11110 = channel 30 (v ddcore ) 01111 =(reserved) (2) 11111 = channel 31 (1.024v band gap) bit 1 go/done : a/d conversion status bit 1 = a/d cycle is in progress. setting this bit starts an a/d conversion cycle. the bit is cleared automatically by hardware when the a/d conversion is completed. 0 = a/d conversion has completed or is not in progress bit 0 adon: a/d on bit 1 = a/d converter is operating 0 = a/d conversion module is shut off and consuming no operating current note 1: these channels are not implemented on 28-pin devices. 2: performing a conversion on unimplemented channels will return random values. 3: channel 28 turns off analog mux switches to allow for minimum capacitive loading of the adc input, for finer resolution ctmu time measurements.
? 2011 microchip technology inc. ds39977d-page 363 pic18f66k80 family register 23-2: adcon1: a/ d control register 1 r/w-0 r/w-0 r/w-0 r/w-0 r/w-x r/w-x r/w-x r/w-x trigsel1 trigsel0 vcfg1 vcfg0 vncfg chsn2 chsn1 chsn0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 trigsel<1:0>: special trigger select bits 11 = selects the special trigger from the ccp2 10 = selects the special trigger from the timer1 01 = selects the special trigger from the ctmu 00 = selects the special trigger from the eccp1 bit 5-4 vcfg<1:0>: a/d v ref + configuration bits 11 = internal v ref + (4.096v) 10 = internal v ref + (2.048v) 01 = external v ref + 00 = av dd bit 3 vncfg: a/d v ref - configuration bit 1 =external v ref 0 =av ss bit 2-0 chsn<2:0>: analog negative channel select bits 111 = channel 07 (an6) 110 = channel 06 (an5) 101 = channel 05 (an4) 100 = channel 04 (an3) 011 = channel 03 (an2) 010 = channel 02 (an1) 001 = channel 01 (an0) 000 = channel 00 (av ss )
pic18f66k80 family ds39977d-page 364 ? 2011 microchip technology inc. register 23-3: adcon2: a/ d control register 2 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 adfm ? acqt2 acqt1 acqt0 adcs2 adcs1 adcs0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 adfm: a/d result format select bit 1 = right justified 0 = left justified bit 6 unimplemented: read as ? 0 ? bit 5-3 acqt<2:0>: a/d acquisition time select bits 111 = 20 t ad 110 = 16 t ad 101 = 12 t ad 100 = 8 t ad 011 = 6 t ad 010 = 4 t ad 001 = 2 t ad 000 = 0 t ad (1) bit 2-0 adcs<2:0>: a/d conversion clock select bits 111 = f rc (clock derived from a/d rc oscillator) (1) 110 = f osc /64 101 = f osc /16 100 = f osc /4 011 = f rc (clock derived from a/d rc oscillator) (1) 010 = f osc /32 001 = f osc /8 000 = f osc /2 note 1: if the a/d frc clock source is selected, a delay of one t cy (instruction cycle) is added before the a/d clock starts. this allows the sleep instruction to be executed before starting a conversion.
? 2011 microchip technology inc. ds39977d-page 365 pic18f66k80 family 23.2.2 a/d result registers the adresh:adresl register pair is where the 12-bit a/d result and extended sign bits (adsgn) are loaded at the completion of a conversion. this register pair is 16 bits wide. the a/d module gives the flexibility of left or right justifying the 12-bit result in the 16-bit result register. the a/d format select bit (adfm) controls this justification. figure 23-3 shows the operation of the a/d result justi- fication and location of the extended sign bits (adsgn). the extended sign bits allow for easier 16-bit math to be performed on the result. when the a/d converter is disabled, these 8-bit registers can be used as tw o, general purpose registers. figure 23-3: a/d result justification register 23-4: adresh: a/d result high byte register, left justified (adfm = 0 ) r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x adres11 adres10 adres9 adres8 adres7 adres6 adres5 adres4 bit 7 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 adres<11:4>: a/d result high byte bits result bits adsgn bits adresh adresl adresh adresl right justified adfm = 1 left justified adfm = 0 12-bit result 2010 _ 18 _0001
pic18f66k80 family ds39977d-page 366 ? 2011 microchip technology inc. register 23-5: adresl: a/d result low byte register, left justified (adfm = 0 ) r/w-x r/w-x u-x u-x u-x u-x u-x r/w-x adres3 adres2 adres1 adres0 adsgn adsgn adsgn adsgn bit 7 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 adres<3:0>: a/d result low byte bits bit 3-0 adsgn: a/d result sign bit 1 = a/d result is negative 0 = a/d result is positive register 23-6: adresh: a/d result high byte register, right justified (adfm = 1 ) u-x u-x u-x u-x r/w-x r/w-x r/w-x r/w-x adsgn adsgn adsgn adsgn adres11 adres10 adres9 adres8 bit 7 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 adsgn: a/d result sign bit 1 = a/d result is negative 0 = a/d result is positive bit 3-0 adres<11:8>: a/d result high byte bits register 23-7: adresl: a/d result low byte register, right justified (adfm = 1 ) r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x adres7 adres6 adres5 adres4 adres3 adres2 adres1 adres0 bit 7 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 adres<7:0>: a/d result low byte bits
? 2011 microchip technology inc. ds39977d-page 367 pic18f66k80 family the anconx registers are used to configure the operation of the i/o pin associated with each analog channel. clearing an anselx bit configures the corresponding pin (anx) to operate as a digital only i/o. setting a bit configures the pin to operate as an analog input for either the a/d converter or the comparator module, with all digital peripherals disabled and digital inputs read as ? 0 ?. as a rule, i/o pins that are multiplexed with analog inputs default to analog operation on any device reset. the analog reference voltage is software selectable to either the device?s positive and negative supply voltage (av dd and av ss ) or the voltage level on the ra3/v ref +/an3 and ra2/v ref -/an2 pins. v ref + has two additional internal voltage reference selections: 2.048v and 4.096v. the a/d converter can uniquely operate while the device is in sleep mode. to operate in sleep , the a/d conversion clock must be derived from the a/d?s internal rc oscillator. the output of the sample and hold is the input into the converter, which generates the result via successive approximation. each port pin associated with the a/d converter can be configured as an analog input or a digital i/o. the adresh and adresl registers contain the result of the a/d conversion. when the a/d conversion is com- plete, the result is loaded into the adresh:adresl register pair, the go/done bit (adcon0<1>) is cleared and the a/d interrupt flag bit, adif (pir1<6>), is set. a device reset forces all registers to their reset state. this forces the a/d module to be turned off and any conversion in progress is aborted. the value in the adresh:adresl register pair is not modified for a power-on reset. these registers will contain unknown data after a power-on reset. the block diagram of the a/d module is shown in figure 23-4 . register 23-8: ancon0: a/d port configuration register 0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ansel7 (1) ansel6 (1) ansel5 (1) ansel4 ansel3 ansel2 ansel1 ansel0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 ansel<7:0>: analog port configuration bits (an7 and an0) (1) 1 = pin configured as an analog channel: digital input disabled and any inputs read as ? 0 ? 0 = pin configured as a digital port note 1: an14 through an11 and an7 to an5 are implemented only on 40/44-pin and 64-pin devices. for 28-pin devices, the corresponding anselx bits are still implemented for these channels, but have no effect. register 23-9: ancon1: a/d port configuration register 1 u-1 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? ansel14 (1) ansel13 (1) ansel12 (1) ansel11 (1) ansel10 ansel9 ansel8 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-0 ansel<14:8>: analog port configuration bits (an14 through an8) (1) 1 = pin configured as an analog channel: digital input disabled and any inputs read as ? 0 ? 0 = pin configured as a digital port note 1: an14 through an11 and an7 to an5 are implemented only on 40/44-pin and 64-pin devices. for 28-pin devices, the corresponding anselx bits are still implemented for these channels, but have no effect.
pic18f66k80 family ds39977d-page 368 ? 2011 microchip technology inc. figure 23-4: a/d block diagram v ref + reference voltage vncfg chs<4:0> an14 (1) an13 (1) an4 an3 an2 an1 an0 01110 01101 00100 00011 00010 00001 00000 12-bit a/d v ref - v ss (2,4) converter 1.024v band gap v ddcore (mux disconnected) (3) (unimplemented) 11111 11110 11101 11100 11011 11010 11001 11000 note 1: channels, an14 through an11, and an7 through an5, are implemented only on 40/44-pin and 64-pin devices. for 28-pin devices, the corresponding anselx bits are still implemented for those channels, but have no effect. 2: i/o pins have diode protection to v dd and v ss . 3: channel 28 turns off analog mux switches to allow for minimum capacitive loading of adc inputs for finer resolution ctmu time measurements. 4: i/o pins have diode protection to v dd and v ss . (unimplemented) (unimplemented) (unimplemented) negative input voltage positive input voltage chsn<2:0> an6 an5 an0 av ss (4) 111 110 001 000 an2 vcfg<1:0> an3 v dd (4) 11 10 01 00 internal v ref + (4.096v) internal v ref + (2.048v) reserved temperature diode
? 2011 microchip technology inc. ds39977d-page 369 pic18f66k80 family after the a/d module has been configured as desired, the selected channel must be acquired before the conversion can start. the analog input channels must have their corresponding tris bits selected as an input. to determine acquisition time, see section 23.3 ?a/d acquisition requirements? . after this acquisi- tion time has elapsed, the a/d conversion can be started. an acquisition time can be programmed to occur between setting the go/done bit and the actual start of the conversion. to do an a/d conversion, follow these steps: 1. configure the a/d module: ? configure the required adc pins as analog pins (ancon0 and ancon1) ? set the voltage reference (adcon1) ? select the a/d positive and negative input channels (adcon0 and adcon1) ? select the a/d acquisition time (adcon2) ? select the a/d conversion clock (adcon2) ? turn on the a/d module (adcon0) 2. configure the a/d interrupt (if desired): ? clear the adif bit (pir1<6>) ? set the adie bit (pie1<6>) ? set the gie bit (intcon<7>) 3. wait the required acquisition time (if required). 4. start the conversion: ? set the go/done bit (adcon0<1>) 5. wait for a/d conversion to complete, by either: ? polling for the go/done bit to be cleared or ? waiting for the a/d interrupt 6. read a/d result registers (adresh:adresl) and, if required, clear bit, adif. 7. for the next conversion, begin with step 1 or 2, as required. the a/d conversion time per bit is defined as t ad . before the next acquisition starts, a minimum wait of 2 t ad is required. figure 23-5: analog input model v ain c pin r s anx 5 pf v dd v t = 0.6v v t = 0.6v i leakage r ic ?? 1k sampling switch ss r ss c hold = 25 pf v ss sampling switch 123 4 (k ? ) v dd 100 na legend: c pin v t i leakage r ic ss c hold = input capacitance = threshold voltage = leakage current at the pin due to = interconnect resistance = sampling switch = sample/hold capacitance (from dac) various junctions = sampling switch resistance r ss
pic18f66k80 family ds39977d-page 370 ? 2011 microchip technology inc. 23.3 a/d acquisition requirements for the a/d converter to meet its specified accuracy, the charge holding (c hold ) capacitor must be allowed to fully charge to the input channel voltage level. the analog input model is shown in figure 23-5 . the source impedance (r s ) and the internal sampling switch (r ss ) impedance directly affect the time required to charge the capacitor c hold . the sampling switch (r ss ) impedance varies over the device voltage (v dd ). the source impedance affects the offset voltage at the analog input (due to pin leakage current). the maxi- mum recommended impedance for analog sources is 2.5 k ? . after the analog input channel is selected or changed, the channel must be sampled for at least the minimum acquisition time before starting a conversion. to calculate the minimum acquisition time, equation 23-1 can be used. this equation assumes that 1/2 lsb error is used (1,024 steps for the a/d). the 1/2 lsb error is the maximum error allowed for the a/d to meet its specified resolution. equation 23-3 shows the calculation of the minimum required acquisition time, t acq . this calculation is based on the following application system assumptions: equation 23-1: acquisition time equation 23-2: a/d minimum charging time equation 23-3: calculating the minimum required acquisition time note: when the conversion is started, the holding capacitor is disconnected from the input pin. c hold =25 pf rs = 2.5 k ?? conversion error ? 1/2 lsb v dd =3v ? rss = 2 k ? temperature = 85 ? c (system max.) t acq = amplifier settling time + holding capacitor charging time + temperature coefficient =t amp + t c + t coff v hold = (v ref ? (v ref /2048)) ? (1 ? e (-t c /c hold (r ic + r ss + r s )) ) or t c = -(c hold )(r ic + r ss + r s ) ln(1/2048) t acq =t amp + t c + t coff t amp =0.2 ? s t coff = (temp ? 25 ? c)(0.02 ? s/ ? c) (85 ? c ? 25 ? c)(0.02 ? s/ ? c) 1.2 ? s temperature coefficient is only required for temperatures > 25 ? c. below 25 ? c, t coff = 0 ms. t c = -(c hold )(r ic + r ss + r s ) ln(1/2048) ? s -(25 pf) (1 k ? + 2 k ? + 2.5 k ? ) ln(0.0004883) ? s 1.05 ? s t acq =0.2 ? s + 1.05 ? s + 1.2 ? s 2.45 ? s
? 2011 microchip technology inc. ds39977d-page 371 pic18f66k80 family 23.4 selecting and configuring automatic acquisition time the adcon2 register allows the user to select an acquisition time that occurs each time the go/done bit is set. when the go/done bit is set, sampling is stopped and a conversion begins. the user is responsible for ensur- ing the required acquisition time has passed between selecting the desired input channel and setting the go/done bit. this occurs when the acqt<2:0> bits (adcon2<5:3>) remain in their reset state (? 000 ?), which is compatible with devices that do not offer programmable acquisition times. if desired, the acqtx bits can be set to select a pro- grammable acquisition time for the a/d module. when the go/done bit is set, the a/d module continues to sample the input for the selected acquisition time, then automatically begins a conversion. since the acquisi- tion time is programmed, there may be no need to wait for an acquisition time between selecting a channel and setting the go/done bit. in either case, when the conversion is completed, the go/done bit is cleared, the adif flag is set and the a/d begins sampling the currently selected channel again. if an acquisition time is programmed, there is nothing to indicate if the acquisition time has ended or if the conversion has begun. 23.5 selecting the a/d conversion clock the a/d conversion time per bit is defined as t ad . the a/d conversion requires 14 t ad per 12-bit conversion. the source of the a/d conversion clock is software selectable. the possible options for t ad are: ?2 t osc ?4 t osc ?8 t osc ?16 t osc ?32 t osc ?64 t osc ? using the internal rc oscillator for correct a/d conversions, the a/d conversion clock (t ad ) must be as short as possible but greater than the minimum t ad . (for more information, see parameter 130 in table 31-26 .) table 23-1 shows the resultant t ad times derived from the device operating frequencies and the a/d clock source selected. table 23-1: t ad vs. device operating frequencies 23.6 configuring analog port pins the ancon0, ancon1, trisa, trisb, trisc and trisc registers control the operation of the a/d port pins. the port pins needed as analog inputs must have their corresponding trisx bits set (input). if the trisx bit is cleared (output), the digital output level (v oh or v ol ) will be converted. the a/d operation is independent of the state of the chs<3:0> bits and the trisx bits. ad clock source (t ad )maximum device frequency operation adcs<2:0> 2 t osc 000 2.50 mhz 4 t osc 100 5.00 mhz 8 t osc 001 10.00 mhz 16 t osc 101 20.00 mhz 32 t osc 010 40.00 mhz 64 t osc 110 64.00 mhz rc (2) x11 1.00 mhz (1) note 1: the rc source has a typical t ad time of 4 ? s. 2: for device frequencies above 1 mhz, the device must be in sleep mode for the entire conversion or the a/d accuracy may be out of specification. note 1: when reading the port register, all pins configured as analog input channels will read as cleared (a low level). pins config- ured as digital inputs will convert an analog input. analog levels on a digitally configured input will be accurately converted. 2: analog levels on any pin defined as a digital input may cause the digital input buffer to consume current out of the device?s specification limits.
pic18f66k80 family ds39977d-page 372 ? 2011 microchip technology inc. 23.7 a/d conversions figure 23-6 shows the operation of the a/d converter after the go/done bit has been set and the acqt<2:0> bits are cleared. a conversion is started after the following instruction to allow entry into sleep mode before the conversion begins. figure 23-7 shows the operation of the a/d converter after the go/done bit has been set, the acqt<2:0> bits set to ? 010 ? and a 4 t ad acquisition time selected. clearing the go/done bit during a conversion will abort the current conversion. the a/d result register pair will not be updated with the partially completed a/d conversion sample. this means the adresh:adresl registers will continue to contain the value of the last completed conversion (or the last value written to the adresh:adresl registers). after the a/d conversion is completed or aborted, a 2t ad wait is required before the next acquisition can be started. after this wait, acquisition on the selected channel is automatically started. figure 23-6: a/d conversion t ad cycles (acqt<2:0> = 000 , t acq = 0 ) figure 23-7: a/d conversion t ad cycles (acqt<2:0> = 010 , t acq = 4 t ad ) note: the go/done bit should not be set in the same instruction that turns on the a/d. t ad 1 t ad 2 t ad 3 t ad 4t ad 5 t ad 6 t ad 7 t ad 8 t ad 11 set go/done bit holding capacitor is disconnected from analog input (typically 100 ns) t ad 9 t ad 10 t cy - t ad next q4: adresh:adresl is loaded, go/done bit is cleared, adif bit is set, holding capacitor is connected to analog input. conversion starts b2 b11 b8 b7 b6 b5 b4 b3 b10 b9 t ad 13 t ad 12 b0 b1 1 2 3 4 5 6 7 8 11 set go/done bit (holding capacitor is disconnected) 9 10 next q4: adresh:adresl is loaded, go/done bit is cleared, adif bit is set, holding capacitor is reconnected to analog input. conversion starts 1 2 3 4 (holding capacitor continues acquiring input) t acqt cycles t ad cycles automatic acquisition time b2 b11 b8 b7 b6 b5 b4 b3 b10 b9 13 12 b0 b1
? 2011 microchip technology inc. ds39977d-page 373 pic18f66k80 family 23.8 use of the special event triggers a/d conversion can be started by the special event trigger of any of these modules: ? ccp2 ? requires ccp2m<3:0> bits (ccp2con<3:0>) set at ? 1011 ? (?) ? eccp1 ? ctmu ? requires the setting of the cttrig bit (ctmuconh<0>) ?timer1 to start an a/d conversion: ? the a/d module must be enabled (adon = 1 ) ? the appropriate analog input channel selected ? the minimum acquisition period set one of these ways: - timing provided by the user - selection made of an appropriate t acq time with these conditions met, the trigger sets the go/done bit and the a/d acquisition starts. if the a/d module is not enabled (adon = 0 ), the module ignores the special event trigger. 23.9 operation in power-managed modes the selection of the automatic acquisition time and a/d conversion clock is determined, in part, by the clock source and frequency while in a power-managed mode. if the a/d is expected to operate while the device is in a power-managed mode, the acqt<2:0> and adcs<2:0> bits in adcon2 should be updated in accordance with the power-managed mode clock that will be used. after the power-managed mode is entered (either of the power-managed run modes), an a/d acquisition or conversion may be started. once an acquisition or con- version is started, the device should continue to be clocked by the same power-managed mode clock source until the conversion has been completed. if desired, the device may be placed into the corresponding power-managed idle mode during the conversion. if the power-managed mode clock frequency is less than 1 mhz, the a/d rc clock source should be selected. operation in sleep mode requires that the a/d rc clock be selected. if bits, acqt<2:0>, are set to ? 000 ? and a conversion is started, the conversion will be delayed one instruction cycle to allow execution of the sleep instruction and entry into sleep mode. the idlen and scs<1:0> bits in the osccon register must have already been cleared prior to starting the conversion. note: with an eccp1 or ccp2 trigger, timer1 or timer3 is cleared. the timers reset to automatically repeat the a/d acquisition period with minimal software overhead (moving adresh:adresl to the desired location). if the a/d module is not enabled, the special event trigger is ignored by the module, but the timer?s counter resets.
pic18f66k80 family ds39977d-page 374 ? 2011 microchip technology inc. table 23-2: registers associated with the a/d module name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif pir1 pspif adif rc1if tx1if sspif tmr1gif tmr2if tmr1if pie1 pspie adie rc1ie tx1ie sspie tmr1gie tmr2ie tmr1ie ipr1 pspip adip rc1ip tx1ip sspip tmr1gip tmr2ip tmr1ip adresh a/d result register high byte adresl a/d result register low byte adcon0 ? chs4 chs3 chs2 chs1 chs0 go/done adon adcon1 trigsel1 trigsel0 vcfg1 vcfg0 vncfg chsn2 chsn1 chsn0 adcon2 adfm ? acqt2 acqt1 acqt0 adcs2 adcs1 adcs0 ancon0 ansel7 ansel6 ansel5 ansel4 ansel3 ansel2 ansel1 ansel0 ancon1 ? ansel14 ansel13 ansel12 ansel11 ansel10 ansel9 ansel8 porta ra7 (1) ra6 (1) ra5 ? ra3 ra2 ra1 ra0 trisa trisa7 (1) trisa6 (1) trisa5 ? trisa3 trisa2 trisa1 trisa0 portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 porte re7 re6 re5 re4 re3 (2) ?re1re0 trise trise7 trise6 trise5 trise4 ? trise2 trise1 trise0 pmd1 pspmd ctmumd adcmd tmr4md tmr3md tmr2md tmr1md tmr0md legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used for a/d conversion. note 1: these bits are available only in certain oscillator modes when the fosc2 configuration bit = 0 . if that configuration bit is cleared, this signal is not implemented. 2: bit is available when master clear is disabled (mclre = 0 ). when mclre is set, the bit is unimplemented.
? 2011 microchip technology inc. ds39977d-page 375 pic18f66k80 family 24.0 comparator module the analog comparator module contains two compara- tors that can be independently configured in a variety of ways. the inputs can be selected from the analog inputs and two internal voltage references. the digital outputs are available at the pin level and can also be read through the control register. multiple output and interrupt event generation are also available. a generic single comparator from the module is shown in figure 24-1 . key features of the module includes: ? independent comparator control ? programmable input configuration ? output to both pin and register levels ? programmable output polarity ? independent interrupt generation for each comparator with configurable interrupt-on-change 24.1 registers the cmxcon registers (cm1con and cm2con) select the input and output configuration for each com- parator, as well as the settings for interrupt generation (see register 24-1 ). the cmstat register ( register 24-2 ) provides the out- put results of the comparators. the bits in this register are read-only. figure 24-1: comparator simplified block diagram cx v in - v in + coe cxout 0 1 2 0 1 cch<1:0> cxinb cxinc c2inb/c2ind (1) cxina cv ref con interrupt logic evpol<1:0> cmpxout (cmstat<7:6>) cmpxif cpol polarity logic cref 3 v bg note 1: comparator 1 uses c2inb as an input to the inverted terminal. comparator 2 uses c1inb as an input to the inverted terminal.
pic18f66k80 family ds39977d-page 376 ? 2011 microchip technology inc. register 24-1: cmxcon: comparator control x register r/w-0 r/w-0 r/w-0 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 con coe cpol evpol1 evpol0 cref cch1 cch0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 con: comparator enable bit 1 = comparator is enabled 0 = comparator is disabled bit 6 coe: comparator output enable bit 1 = comparator output is present on the cxout pin 0 = comparator output is internal only bit 5 cpol: comparator output polarity select bit 1 = comparator output is inverted 0 = comparator output is not inverted bit 4-3 evpol<1:0>: interrupt polarity select bits 11 = interrupt generation on any change of the output (1) 10 = interrupt generation only on high-to-low transition of the output 01 = interrupt generation only on low-to-high transition of the output 00 = interrupt generation is disabled bit 2 cref: comparator reference select bit (non-inverting input) 1 = non-inverting input connects to internal cv ref voltage 0 = non-inverting input connects to cxina pin bit 1-0 cch<1:0>: comparator channel select bits 11 = inverting input of comparator connects to v bg 10 = inverting input of comparator connects to c2inb pin (2) 01 = inverting input of comparator connects to cxinc pin 00 = inverting input of comparator connects to c1inb pin (2) note 1: the cmpxif is automatically set any time this mode is selected and must be cleared by the application after the initial configuration. 2: comparator 1 uses c2inb as an input to the inverting terminal. comparator 2 uses c1inb as an input to the inverted terminal.
? 2011 microchip technology inc. ds39977d-page 377 pic18f66k80 family register 24-2: cmstat: comparator status register r-x r-x u-0 u-0 u-0 u-0 u-0 u-0 cmp2out cmp1out ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 cmp2out:cmp1out: comparator x status bits if cpol (cmxcon<5>)= 0 (non-inverted polarity): 1 = comparator x?s v in + > v in - 0 = comparator x?s v in + < v in - if cpol = 1 (inverted polarity): 1 = comparator x?s v in + < v in - 0 = comparator x?s v in + > v in - bit 4-0 unimplemented: read as ? 0 ?
pic18f66k80 family ds39977d-page 378 ? 2011 microchip technology inc. 24.2 comparator operation a single comparator is shown in figure 24-2 , along with the relationship between the analog input levels and the digital output. when the analog input at v in + is less than the analog input, v in -, the output of the compara- tor is a digital low level. when the analog input at v in + is greater than the analog input, v in -, the output of the comparator is a digital high level. the shaded areas of the output of the comparator in figure 24-2 represent the uncertainty due to input offsets and response time. figure 24-2: single comparator 24.3 comparator response time response time is the minimum time, after selecting a new reference voltage or input source, before the com- parator output has a valid level. the response time of the comparator differs from the settling time of the volt- age reference. therefore, both of these times must be considered when determining the total response to a comparator input change. otherwise, the maximum delay of the comparators should be used (see section 31.0 ?electrical characteristics? ). 24.4 analog input connection considerations a simplified circuit for an analog input is shown in figure 24-3 . since the analog pins are connected to a digital output, they have reverse biased diodes to v dd and v ss . the analog input, therefore, must be between v ss and v dd . if the input voltage deviates from this range by more than 0.6v in either direction, one of the diodes is forward biased and a latch-up condition may occur. a maximum source impedance of 10 k ? is recommended for the analog sources. any external component connected to an analog input pin, such as a capacitor or a zener diode, should have very little leakage current. figure 24-3: comparator analog input model output v in - v in + ? + v in + v in - output va r s a in c pin 5 pf v dd v t = 0.6v v t = 0.6v r ic i leakage 100 na v ss legend: c pin = input capacitance v t = threshold voltage i leakage = leakage current at the pin due to various junctions r ic = interconnect resistance r s = source impedance va = analog voltage comparator input <10 k ?
? 2011 microchip technology inc. ds39977d-page 379 pic18f66k80 family 24.5 comparator control and configuration each comparator has up to eight possible combina- tions of inputs: up to four external analog inputs and one of two internal voltage references. all of the comparators allow a selection of the signal from pin, cxina, or the voltage from the comparator reference (cv ref ) on the non-inverting channel. this is compared to either c1inb, cxinc, c2inb or the micro- controller?s fixed internal reference voltage (v bg , 1.024v nominal) on the inverting channel. the compar- ator inputs and outputs are tied to fixed i/o pins, defined in table 24-1 . the available comparator config- urations and their corresponding bit settings are shown in figure 24-4 . table 24-1: comparator inputs and outputs 24.5.1 comparator enable and input selection setting the con bit of the cmxcon register (cmxcon<7>) enables the comparator for operation. clearing the con bit disables the comparator, resulting in minimum current consumption. the cch<1:0> bits in the cmxcon register (cmxcon<1:0>) direct either one of three analog input pins, or the internal reference voltage (v bg ), to the comparator, v in -. depending on the comparator oper- ating mode, either an external or internal voltage reference may be used. the analog signal present at v in - is compared to the signal at v in + and the digital output of the comparator is adjusted accordingly. the external reference is used when cref = 0 (cmxcon<2>) and v in + is connected to the cxina pin. when external voltage references are used, the comparator module can be configured to have the ref- erence sources externally. the reference signal must be between v ss and v dd and can be applied to either pin of the comparator. the comparator module also allows the selection of an internally generated voltage reference (cv ref ) from the comparator voltage reference module. this module is described in more detail in section 25.0 ?comparator voltage reference module? . the reference from the comparator voltage reference module is only available when cref = 1 . in this mode, the internal voltage reference is applied to the comparator?s v in + pin. 24.5.2 comparator enable and output selection the comparator outputs are read through the cmstat register. the cmstat<6> bit reads the comparator 1 output, cmstat<7> reads the comparator 2 output. these bits are read-only. the comparator outputs may also be directly output to the re2 and re1 pins by setting the coe bit (cmxcon<6>). when enabled, multiplexers in the output path of the pins switch to the output of the com- parator. while in this mode, the trise<2:1> bits still function as the digital output enable bits for the re2, and re1 pins. by default, the comparator?s output is at logic high whenever the voltage on v in + is greater than on v in -. the polarity of the comparator outputs can be inverted using the cpol bit (cmxcon<5>). the uncertainty of each of the comparators is related to the input offset voltage and the response time given in the specifications, as discussed in section 24.2 ?comparator operation? . comparator input or output i/o pin (?) 1 c1ina (v in +) rb0/rd0 c1inb (v in -) rb1/rd1 c1inc (v in -) ra1 c2inb(v in -) ra5/rd3 c1out rb2/re1 2 c2ina(v in +) rb4/rd2 c2inb(v in -) ra5/rd3 c2inc(v in -) ra2 c2out rb3/re2 ? the i/o pin is dependent on package type. note: the comparator input pin selected by cch<1:0> must be configured as an input by setting both the corresponding tris bit and the corresponding anselx bit in the anconx register.
pic18f66k80 family ds39977d-page 380 ? 2011 microchip technology inc. figure 24-4: comparator configurations cx v in - v in + off (read as ? 0 ?) comparator off con = 0 , cref = x , cch<1:0> = xx coe cx v in - v in + coe comparator cxinb > cxina compare con = 1 , cref = 0 , cch<1:0> = 00 cxinb cxina cx v in - v in + coe comparator cxinc > cxina compare con = 1 , cref = 0 , cch<1:0> = 01 cxinc cxina cx v in - v in + coe comparator c2inb/c1inb > cxina compare con = 1 , cref = 0 , cch<1:0> = 10 c1inb cxina cx v in - v in + coe comparator v bg > cxina compare con = 1 , cref = 0 , cch<1:0> = 11 v bg cxina cx v in - v in + coe comparator cxinb > cv ref compare con = 1 , cref = 1 , cch<1:0> = 00 cxinb cv ref cx v in - v in + coe comparator cxinc > cv ref compare con = 1 , cref = 1 , cch<1:0> = 01 cxinc cv ref cx v in - v in + coe comparator c2inb/c1inb > cv ref compare con = 1 , cref = 1 , cch<1:0> = 10 cv ref cx v in - v in + coe pin comparator v bg > cv ref compare con = 1 , cref = 1 , cch<1:0> = 11 v bg cv ref cxout note 1: v bg is the internal reference voltage (see table 31-2 ). pin cxout pin cxout pin cxout pin cxout pin cxout pin cxout pin cxout pin cxout c2inb/ c1inb c2inb/
? 2011 microchip technology inc. ds39977d-page 381 pic18f66k80 family 24.6 comparator interrupts the comparator interrupt flag is set whenever any of the following occurs: ? low-to-high transition of the comparator output ? high-to-low transition of the comparator output ? any change in the comparator output the comparator interrupt selection is done by the evpol<1:0> bits in the cmxcon register (cmxcon<4:3>). in order to provide maximum flexibility, the output of the comparator may be inverted using the cpol bit in the cmxcon register (cmxcon<5>). this is functionally identical to reversing the inverting and non-inverting inputs of the comparator for a particular mode. an interrupt is generated on the low-to-high or high-to- low transition of the comparator output. this mode of interrupt generation is dependent on evpol<1:0> in the cmxcon register. when evpol<1:0> = 01 or 10 , the interrupt is generated on a low-to-high or high-to- low transition of the comparator output. once the interrupt is generated, it is required to clear the interrupt flag by software. when evpol<1:0> = 11 , the comparator interrupt flag is set whenever there is a change in the output value of either comparator. software will need to maintain information about the status of the output bits, as read from cmstat<7:6>, to determine the actual change that occurred. the cmpxif<2:0> (pir4<5:4) bits are the comparator interrupt flags. the cmpxif bits must be reset by clearing them. since it is also possible to write a ? 1 ? to this register, a simulated interrupt may be initiated. table 24-2 shows the interrupt generation with respect to comparator input voltages and evpol bit settings. both the cmpxie bits (pie4<5:4>) and the peie bit (intcon<6>) must be set to enable the interrupt. in addition, the gie bit (intcon<7>) must also be set. if any of these bits are clear, the interrupt is not enabled, though the cmpxif bits will still be set if an interrupt condition occurs. a simplified diagram of the interrupt section is shown in figure 24-3 . table 24-2: comparator interrupt generation note: cmpxif will not be set when evpol<1:0> = 00 . cpol evpol<1:0> comparator input change cxout transition interrupt generated 0 00 v in + > v in - low-to-high no v in + < v in -high-to-low no 01 v in + > v in - low-to-high yes v in + < v in -high-to-low no 10 v in + > v in - low-to-high no v in + < v in -high-to-low yes 11 v in + > v in - low-to-high yes v in + < v in -high-to-low yes 1 00 v in + > v in -high-to-low no v in + < v in - low-to-high no 01 v in + > v in -high-to-low no v in + < v in - low-to-high yes 10 v in + > v in -high-to-low yes v in + < v in - low-to-high no 11 v in + > v in -high-to-low yes v in + < v in - low-to-high yes
pic18f66k80 family ds39977d-page 382 ? 2011 microchip technology inc. 24.7 comparator operation during sleep when a comparator is active and the device is placed in sleep mode, the comparator remains active and the interrupt is functional, if enabled. this interrupt will wake-up the device from sleep mode, when enabled. each operational comparator will consume additional current. to minimize power consumption while in sleep mode, turn off the comparators (con = 0 ) before entering sleep. if the device wakes up from sleep, the contents of the cmxcon register are not affected. 24.8 effects of a reset a device reset forces the cmxcon registers to their reset state. this forces both comparators and the voltage reference to the off state. table 24-3: registers associated with comparator module name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif cm1con con coe cpol evpol1 evpol0 cref cch1 cch0 cm2con con coe cpol evpol1 evpol0 cref cch1 cch0 cvrcon cvren cvroe cvrss cvr4 cvr3 cvr2 cvr1 cvr0 cmstat cmp2out cmp1out ? ? ? ? ? ? pir4 tmr4if eeif cmp2if cmp1if ? ccp5if ccp4if ccp3if pie4 tmr4ie eeie cmp2ie cmp1ie ? ccp5ie ccp4ie ccp3ie ipr4 tmr4ip eeip cmp2ip cmp1ip ? ccp5ip ccp4ip ccp3ip ancon0 ansel7 ansel6 ansel5 ansel4 ansel3 ansel2 ansel1 ansel0 ancon1 ? ansel14 ansel13 ansel12 ansel11 ansel10 ansel9 ansel8 pmd2 ? ? ? ? modmd ecanmd cmp2md cmp1md legend: ? = unimplemented, read as ? 0 ?.
? 2011 microchip technology inc. ds39977d-page 383 pic18f66k80 family 25.0 comparator voltage reference module the comparator voltage reference is a 32-tap resistor ladder network that provides a selectable reference voltage. although its primary purpose is to provide a reference for the analog comparators, it may also be used independently of them. a block diagram of the module is shown in figure 25-1 . the resistor ladder is segmented to provide a range of cv ref values and has a power-down function to conserve power when the reference is not being used. the module?s supply reference can be provided from either device v dd /v ss or an external voltage reference. 25.1 configuring the comparator voltage reference the comparator voltage reference module is controlled through the cvrcon register ( register 25-1 ). the comparator voltage reference provides a range of output voltage with 32 levels. the cvr<4:0> selection bits (cvrcon<4:0>) offer a range of output voltages. equation 25-1 shows the how the comparator voltage reference is computed. equation 25-1: the comparator reference supply voltage can come from either v dd and v ss , or the external v ref + and v ref - that are multiplexed with ra3 and ra2. the voltage source is selected by the cvrss bit (cvrcon<5>). the settling time of the comparator voltage reference must be considered when changing the cv ref output (see table 31-2 in section 31.0 ?electrical characteristics? ). if cvrss = 1 : cv ref = v ref - + ? (v ref + ? v ref -) cvr<4:0> 32 () if cvrss = 0 : cv ref = av ss + ? (av dd ? av ss ) cvr<4:0> 32 () register 25-1: cvrcon: comparator vo ltage reference control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 cvren cvroe cvrss cvr4 cvr3 cvr2 cvr1 cvr0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 cvren: comparator voltage reference enable bit 1 =cv ref circuit powered on 0 =cv ref circuit powered down bit 6 cvroe: comparator v ref output enable bit 1 =cv ref voltage level is output on cv ref pin 0 =cv ref voltage level is disconnected from cv ref pin bit 5 cvrss: comparator v ref source selection bit 1 = comparator reference source, cv rsrc = v ref +?v ref - 0 = comparator reference source, cv rsrc = av dd ?av ss bit 4-0 cvr<4:0>: comparator v ref value selection 0 ? cvr<4:0> ? 31 bits when cvrss = 1 : cv ref = (v ref -) + (cvr<4:0>/32) ? (v ref + ? v ref -) when cvrss = 0 : cv ref = (av ss ) + (cvr<4:0>/32) ? (av dd ? av ss )
pic18f66k80 family ds39977d-page 384 ? 2011 microchip technology inc. figure 25-1: comparator voltage reference block diagram 25.2 voltage reference accuracy/error the full range of voltage reference cannot be realized due to the construction of the module. the transistors on the top and bottom of the resistor ladder network ( figure 25-1 ) keep cv ref from approaching the refer- ence source rails. the voltage reference is derived from the reference source; therefore, the cv ref output changes with fluctuations in that source. the tested absolute accuracy of the voltage reference can be found in section 31.0 ?electrical characteristics? . 25.3 operation during sleep when the device wakes up from sleep through an interrupt or a watchdog timer time-out, the contents of the cvrcon register are not affected. to minimize current consumption in sleep mode, the voltage reference should be disabled. 25.4 effects of a reset a device reset disables the voltage reference by clearing bit, cvren (cvrcon<7>). this reset also disconnects the reference from the rf5 pin by clearing bit, cvroe (cvrcon<6>). 25.5 connection considerations the voltage reference module operates independently of the comparator module. the output of the reference generator may be connected to the ra0 pin if the cvroe bit is set. enabling the voltage reference out- put onto ra0 when it is configured as a digital input will increase current consumption. connecting ra0 as a digital output with cvrss enabled will also increase current consumption. the ra0 pin can be used as a simple d/a output with limited drive capability. due to the limited current drive capability, a buffer must be used on the voltage reference output for external connections to v ref . figure 25-2 shows an example buffering technique. 32-to-1 mux cvr<4:0> 8r r cvren cvrss = 0 av dd v ref + cvrss = 1 r r r r r r 32 steps cv ref v ref - cvrss = 1 cvrss = 0
? 2011 microchip technology inc. ds39977d-page 385 pic18f66k80 family figure 25-2: comparator voltage reference output buffer example table 25-1: registers associated with comparator voltage reference name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 cvrcon cvren cvroe cvrss cvr4 cvr3 cvr2 cvr1 cvr0 cm1con con coe cpol evpol1 evpol0 cref cch1 cch0 cm2con con coe cpol evpol1 evpol0 cref cch1 cch0 trisa trisa7 trisa6 trisa5 ? trisa3 trisa2 trisa1 trisa0 ancon0 ansel7 ansel6 ansel5 ansel4 ansel3 ansel2 ansel1 ansel0 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used with the comparator voltage reference. cv ref output + ? cv ref module voltage reference output impedance r (1) ra0 pic18f66k80 note 1: r is dependent upon the voltage reference configuration bits, cvrcon<3:0> and cvrcon<5>.
pic18f66k80 family ds39977d-page 386 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds39977d-page 387 pic18f66k80 family 26.0 high/low-voltage detect (hlvd) the pic18f66k80 family of devices has a high/low- voltage detect module (hlvd). this is a programmable circuit that sets both a device voltage trip point and the direction of change from that point. if the device experi- ences an excursion past the trip point in that direction, an interrupt flag is set. if the interrupt is enabled, the pro- gram execution branches to the interrupt vector address and the software responds to the interrupt. the high/low-voltage detect control register ( register 26-1 ) completely controls the operation of the hlvd module. this allows the circuitry to be ?turned off? by the user under software control, which minimizes the current consumption for the device. the module?s block diagram is shown in figure 26-1 . register 26-1: hlvdcon: high/low-v oltage detect control register r/w-0 r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 vdirmag bgvst irvst hlvden hlvdl3 (1) hlvdl2 (1) hlvdl1 (1) hlvdl0 (1) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 vdirmag: voltage direction magnitude select bit 1 = event occurs when voltage equals or exceeds trip point (hlvdl<3:0>) 0 = event occurs when voltage equals or falls below trip point (hlvdl<3:0>) bit 6 bgvst: band gap reference voltages stable status flag bit 1 = internal band gap voltage references are stable 0 = internal band gap voltage references are not stable bit 5 irvst: internal reference voltage stable flag bit 1 = indicates that the voltage detect logic will generate the interrupt flag at the specified voltage range 0 = indicates that the voltage detect logic will not generate the interrupt flag at the specified voltage range and the hlvd interrupt should not be enabled bit 4 hlvden: high/low-voltage detect power enable bit 1 = hlvd enabled 0 = hlvd disabled bit 3-0 hlvdl<3:0>: voltage detection limit bits (1) 1111 = external analog input is used (input comes from the hlvdin pin) 1110 = maximum setting . . . 0000 = minimum setting note 1: for the electrical specifications, see parameter d042 in section 31.0 ?electrical characteristics? .
pic18f66k80 family ds39977d-page 388 ? 2011 microchip technology inc. the module is enabled by setting the hlvden bit (hlvdcon<4>). each time the hlvd module is enabled, the circuitry requires some time to stabilize. the irvst bit (hlvdcon<5>) is a read-only bit used to indicate when the circuit is stable. the module can only generate an interrupt after the circuit is stable and irvst is set. the vdirmag bit (hlvdcon<7>) determines the overall operation of the module. when vdirmag is cleared, the module monitors for drops in v dd below a predetermined set point. when the bit is set, the module monitors for rises in v dd above the set point. 26.1 operation when the hlvd module is enabled, a comparator uses an internally generated reference voltage as the set point. the set point is compared with the trip point, where each node in the resistor divider represents a trip point voltage. the ?trip point? voltage is the voltage level at which the device detects a high or low-voltage event, depending on the configuration of the module. when the supply voltage is equal to the trip point, the voltage tapped off of the resistor array is equal to the internal reference voltage generated by the voltage reference module. the comparator then generates an interrupt signal by setting the hlvdif bit. the trip point voltage is software programmable to any one of 16 values. the trip point is selected by programming the hlvdl<3:0> bits (hlvdcon<3:0>). the hlvd module has an additional feature that allows the user to supply the trip voltage to the module from an external source. this mode is enabled when bits, hlvdl<3:0>, are set to ? 1111 ?. in this state, the comparator input is multiplexed from the external input pin, hlvdin. this gives users the flexibility of configur- ing the high/low-voltage detect interrupt to occur at any voltage in the valid operating range. figure 26-1: hlvd module block diagram (with external input) set v dd 16-to-1 mux hlvden hlvdcon hlvdl<3:0> register hlvdin v dd externally generated trip point hlvdif hlvden boren internal voltage reference vdirmag 1.024v typical
? 2011 microchip technology inc. ds39977d-page 389 pic18f66k80 family 26.2 hlvd setup to set up the hlvd module: 1. select the desired hlvd trip point by writing the value to the hlvdl<3:0> bits. 2. set the vdirmag bit to detect high voltage (vdirmag = 1 ) or low voltage (vdirmag = 0 ). 3. enable the hlvd module by setting the hlvden bit. 4. clear the hlvd interrupt flag (pir2<2>), which may have been set from a previous interrupt. 5. if interrupts are desired, enable the hlvd interrupt by setting the hlvdie and gie bits (pie2<2> and intcon<7>, respectively). an interrupt will not be generated until the irvst bit is set. 26.3 current consumption when the module is enabled, the hlvd comparator and voltage divider are enabled and consume static current. the total current consumption, when enabled, is specified in electrical specification parameter d022b ( ? ihlvd) ( tab l e 3 1- 11 ). depending on the application, the hlvd module does not need to operate constantly. to reduce current requirements, the hlvd circuitry may only need to be enabled for short periods where the voltage is checked. after such a check, the module could be disabled. 26.4 hlvd start-up time the internal reference voltage of the hlvd module, specified in electrical specification parameter 37 ( section 31.0 ?electrical characteristics? ), may be used by other internal circuitry, such as the programmable brown-out reset. if the hlvd or other circuits using the voltage reference are disabled to lower the device?s current consumption, the reference voltage circuit will require time to become stable before a low or high-voltage condition can be reliably detected. this start-up time, t irvst , is an interval that is independent of device clock speed. it is specified in electrical specification parameter 37 ( table 31-11 ). the hlvd interrupt flag is not enabled until t irvst has expired and a stable reference voltage is reached. for this reason, brief excursions beyond the set point may not be detected during this interval (see figure 26-2 or figure 26-3). note: before changing any module settings (v dirmag , hlvdl<3:0>), first disable the module (hlvden = 0 ), make the changes and re-enable the module. this prevents the generation of false hlvd events.
pic18f66k80 family ds39977d-page 390 ? 2011 microchip technology inc. figure 26-2: low-voltage detect operation (vdirmag = 0 ) v hlvd v dd hlvdif v hlvd v dd enable hlvd t irvst hlvdif may not be set enable hlvd hlvdif hlvdif cleared in software hlvdif cleared in software hlvdif cleared in software, case 1: case 2: hlvdif remains set since hlvd condition still exists t irvst internal reference is stable internal reference is stable irvst irvst
? 2011 microchip technology inc. ds39977d-page 391 pic18f66k80 family figure 26-3: high-voltage detect operation (vdirmag = 1 ) 26.5 applications in many applications, it is desirable to detect a drop below, or rise above, a particular voltage threshold. for example, the hlvd module could be periodically enabled to detect universal serial bus (usb) attach or detach. this assumes the device is powered by a lower voltage source than the usb when detached. an attach would indicate a high-voltage detect from, for example, 3.3v to 5v (the voltage on usb) and vice versa for a detach. this feature could save a design a few extra components and an attach signal (input pin). for general battery applications, figure 26-4 shows a possible voltage curve. over time, the device voltage decreases. when the device voltage reaches voltage, v a , the hlvd logic generates an interrupt at time, t a . the interrupt could cause the execution of an isr, which would allow the application to perform ?house- keeping tasks? and a controlled shutdown before the device voltage exits the valid operating range at t b . this would give the application a time window, repre- sented by the difference between t a and t b , to safely exit. figure 26-4: typical low-voltage detect application v hlvd v dd hlvdif v hlvd v dd enable hlvd t irvst hlvdif may not be set enable hlvd hlvdif hlvdif cleared in software hlvdif cleared in software hlvdif cleared in software, case 1: case 2: hlvdif remains set since hlvd condition still exists t irvst irvst internal reference is stable internal reference is stable irvst time voltage v a v b t a t b v a = hlvd trip point v b = minimum valid device operating voltage legend:
pic18f66k80 family ds39977d-page 392 ? 2011 microchip technology inc. 26.6 operation during sleep when enabled, the hlvd circuitry continues to operate during sleep. if the device voltage crosses the trip point, the hlvdif bit will be set and the device will wake-up from sleep. device execution will continue from the interrupt vector address if interrupts have been globally enabled. 26.7 effects of a reset a device reset forces all registers to their reset state. this forces the hlvd module to be turned off. table 26-1: registers associated wi th high/low-voltage detect module name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 hlvdcon vdirmag bgvst irvst hlvden hlvdl3 hlvdl2 hlvdl1 hlvdl0 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif pir2 oscfif ? ? ? bclif hlvdif tmr3if tmr3gif pie2 oscfie ? ? ? bclie hlvdie tmr3ie tmr3gie ipr2 oscfip ? ? ? bclip hlvdip tmr3ip tmr3gip trisa trisa7 (1) trisa6 (1) trisa5 ? trisa3 trisa2 trisa1 trisa0 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the hlvd module. note 1: porta<7:6> and their direction bits are individually configured as port pins based on various primary oscillator modes. when disabled, these bits read as ? 0 ?.
? 2011 microchip technology inc. ds39977d-page 393 pic18f66k80 family 27.0 ecan module pic18f66k80 family devices contain an enhanced controller area network (ecan) module. the ecan module is fully backward compatible with the can module available in pic18cxx8 and pic18fxx8 devices and the ecan module in pic18fxx80 devices. the controller area network (can) module is a serial interface which is useful for communicating with other peripherals or microcontroller devices. this interface, or protocol, was designed to allow communications within noisy environments. the ecan module is a communication controller, imple- menting the can 2.0a or b protocol as defined in the bosch specification. the module will support can 1.2, can 2.0a, can 2.0b passive and can 2.0b active versions of the protocol. the module implementation is a full can system; however, the can specification is not covered within this data sheet. refer to the bosch can specification for further details. the module features are as follows: ? implementation of the can protocol, can 1.2, can 2.0a and can 2.0b ? devicenet tm data bytes filter support ? standard and extended data frames ? 0-8 bytes data length ? programmable bit rate up to 1 mbit/sec ? fully backward compatible with the pic18xxx8 can module ? three modes of operation: - mode 0 ? legacy mode - mode 1 ? enhanced legacy mode with devicenet support - mode 2 ? fifo mode with devicenet support ? support for remote frames with automated handling ? double-buffered receiver with two prioritized received message storage buffers ? six buffers programmable as rx and tx message buffers ? 16 full (standard/extended identifier) acceptance filters that can be linked to one of four masks ? two full acceptance filter masks that can be assigned to any filter ? one full acceptance filter that can be used as either an acceptance filter or acceptance filter mask ? three dedicated transmit buffers with application specified prioritization and abort capability ? programmable wake-up functionality with integrated low-pass filter ? programmable loopback mode supports self-test operation ? signaling via interrupt capabilities for all can receiver and transmitter error states ? programmable clock source ? programmable link to timer module for time-stamping and network synchronization ? low-power sleep mode 27.1 module overview the can bus module consists of a protocol engine and message buffering and control. the can protocol engine automatically handles all functions for receiving and transmitting messages on the can bus. messages are transmitted by first loading the appropriate data registers. status and errors can be checked by reading the appropriate registers. any message detected on the can bus is checked for errors and then matched against filters to see if it should be received and stored in one of the two receive registers. the can module supports the following frame types: ? standard data frame ? extended data frame ? remote frame ? error frame ? overload frame reception the can module uses the rb2/cantx and rb3/ canrx pins to interface with the can bus. the cantx and canrx pins can be placed on alternate i/o pins by setting the canmx (config3h<0>) configuration bit. for the pic18f2xk80 and pic18f4xk80, the alter- nate pin locations are rc6/cantx and rc7/canrx. for the pic18f6xk80, the alternate pin locations are re4/canrx and re5/cantx. in normal mode, the can module automatically over- rides the appropriate tris bit for cantx. the user must ensure that the appropriate tris bit for canrx is set. 27.1.1 module functionality the can bus module consists of a protocol engine, message buffering and control (see figure 27-1). the protocol engine can best be understood by defining the types of data frames to be transmitted and received by the module. the following sequence illustrates the necessary initial- ization steps before the ecan module can be used to transmit or receive a message. steps can be added or removed depending on the requirements of the application. 1. initial lat and tris bits for rx and tx can. 2. ensure that the ecan module is in configuration mode. 3. select ecan operational mode. 4. set up the baud rate registers. 5. set up the filter and mask registers. 6. set the ecan module to normal mode or any other mode required by the application logic.
pic18f66k80 family ds39977d-page 394 ? 2011 microchip technology inc. figure 27-1: can buffers and protoc ol engine block diagram msgreq txb2 abtf mloa txerr mtxbuff message message queue control transmit byte sequencer msgreq txb1 abtf mloa txerr mtxbuff message msgreq txb0 abtf mloa txerr mtxbuff message acceptance filters (rxf0-rxf05) a c c e p t data field identifier acceptance mask rxm1 acceptance filters (rxf06-rxf15) m a b acceptance mask rxm0 rcv byte 16 - 4 to 1 muxs protocol message buffers transmit option mode 0 mode 1, 2 6 tx/rx buffers 2 rx buffers crc<14:0> comparator receive<8:0> transmit<7:0> receive error transmit error protocol rec tec err-pas bus-off finite state machine counter counter shift<14:0> {transmit<5:0>, receive<8:0>} transmit logic bit timing logic tx rx configuration registers clock generator buffers engine mode 0 mode 1, 2 rxf15 v cc
? 2011 microchip technology inc. ds39977d-page 395 pic18f66k80 family 27.2 can module registers there are many control and data registers associated with the can module. for convenience, their descriptions have been grouped into the following sections: ? control and status registers ? dedicated transmit buffer registers ? dedicated receive buffer registers ? programmable tx/rx and auto rtr buffers ? baud rate control registers ? i/o control register ? interrupt status and control registers detailed descriptions of each register and their usage are described in the following sections. 27.2.1 can control and status registers the registers described in this section control the overall operation of the can module and show its operational status. note: not all can registers are available in the access bank.
pic18f66k80 family ds39977d-page 396 ? 2011 microchip technology inc. register 27-1: cancon: can control register mode 0 r/w-1 r/w-0 r/w-0 r/s-0 r/w-0 r/w-0 r/w-0 u-0 reqop2 reqop1 reqop0 abat win2 win1 win0 ? mode 1 r/w-1 r/w-0 r/w-0 r/s-0 u0 u-0 u-0 u-0 reqop2 reqop1 reqop0 abat ? ? ? ? mode 2 r/w-1 r/w-0 r/w-0 r/s-0 r-0 r-0 r-0 r-0 reqop2 reqop1 reqop0 abat fp3 fp2 fp1 fp0 bit 7 bit 0 legend: s = settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 reqop<2:0>: request can operation mode bits 1xx = request configuration mode 011 = request listen only mode 010 = request loopback mode 001 = disabled/sleep mode 000 = request normal mode bit 4 abat: abort all pending transmissions bit 1 = abort all pending transmissions (in all transmit buffers) (1) 0 = transmissions proceeding as normal bit 3-1 mode 0: win<2:0>: window address bits these bits select which of the can buffers to switch into the access bank area. this allows access to the buffer registers from any data memory bank. after a frame has caused an interrupt, the icode<3:0> bits can be copied to the win<2:0> bits to select the correct buffer. see example 27-2 for a code example. 111 = receive buffer 0 110 = receive buffer 0 101 = receive buffer 1 100 = transmit buffer 0 011 = transmit buffer 1 010 = transmit buffer 2 001 = receive buffer 0 000 = receive buffer 0 bit 0 mode 0: unimplemented: read as ? 0 ? bit 4-0 mode 1: unimplemented: read as ? 0 ? mode 2: fp<3:0>: fifo read pointer bits these bits point to the message buffer to be read. 0000 = receive message buffer 0 0001 = receive message buffer 1 0010 = receive message buffer 2 0011 = receive message buffer 3 0100 = receive message buffer 4 0101 = receive message buffer 5 0110 = receive message buffer 6 0111 = receive message buffer 7 1000:1111 reserved note 1: this bit will clear when all transmissions are aborted.
? 2011 microchip technology inc. ds39977d-page 397 pic18f66k80 family register 27-2: canstat: can status register mode 0 r-1 r-0 r-0 r-0 r-0 r-0 r-0 u-0 opmode2 (1) opmode1 (1) opmode0 (1) ? icode2 icode1 icode0 ? mode 1,2 r-1 r-0 r-0 r-0 r-0 r-0 r-0 r-0 opmode2 (1) opmode1 (1) opmode0 (1) eicode4 eicode3 eicode2 eicode1 eicode0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 opmode<2:0>: operation mode status bits (1) 111 = reserved 110 = reserved 101 = reserved 100 = configuration mode 011 = listen only mode 010 = loopback mode 001 = disable/sleep mode 000 = normal mode bit 4 mode 0: unimplemented: read as ? 0 ? bit 3-1,4-0 mode 0: icode<2:0>: interrupt code bits when an interrupt occurs, a prioritized coded interrupt value will be present in these bits. this code indicates the source of the interrupt. by copying icode<3:1> to win<3:0> (mode 0) or eicode<4:0> to ewin<4:0> (mode 1 and 2), it is possible to select the correct buffer to map into the access bank area. see example 27-2 for a code example. to simplify the description, the following table lists all five bits. bit 0 mode 0: unimplemented: read as ? 0 ? bit 4-0 mode 1, 2: eicode<4:0>: interrupt code bits see icode<3:1> above. note 1: to achieve maximum power saving and/or able to wake-up on can bus activity, switch the can module in disable/sleep mode before putting the device to sleep. 2: if the buffer is configured as a receiver, the eicode bits will contain ? 10000 ? upon interrupt. mode 0 mode 1 mode 2 no interrupt 00000 00000 00000 can bus error interrupt 00010 00010 00010 txb2 interrupt 00100 00100 00100 txb1 interrupt 00110 00110 00110 txb0 interrupt 01000 01000 01000 rxb1 interrupt 01010 10001 ----- rxb0 interrupt 01100 10000 10000 wake-up interrupt 00010 01110 01110 rxb0 interrupt ----- 10000 10000 rxb1 interrupt ----- 10001 10000 rx/tx b0 interrupt ----- 10010 10010 (2) rx/tx b1 interrupt ----- 10011 10011 (2) rx/tx b2 interrupt ----- 10100 10100 (2) rx/tx b3 interrupt ----- 10101 10101 (2) rx/tx b4 interrupt ----- 10110 10110 (2) rx/tx b5 interrupt ----- 10111 10111 (2)
pic18f66k80 family ds39977d-page 398 ? 2011 microchip technology inc. example 27-1: changing to configuration mode example 27-2: win and icode bits usage in interrupt service routine to access tx/rx buffers ; request configuration mode. movlw b?10000000? ; set to configuration mode. movwf cancon ; a request to switch to configuration mode may not be immediately honored. ; module will wait for can bus to be idle before switching to configuration mode. ; request for other modes such as loopback, disable etc. may be honored immediately. ; it is always good practice to wait and verify before continuing. configwait: movf canstat, w ; read current mode state. andlw b?10000000? ; interested in opmode bits only. tstfsz wreg ; is it configuration mode yet? bra configwait ; no. continue to wait... ; module is in configuration mode now. ; modify configuration registers as required. ; switch back to normal mode to be able to communicate. ; save application required context. ; poll interrupt flags and determine source of interrupt ; this was found to be can interrupt ; tempcancon and tempcanstat are variables defined in access bank low movff cancon, tempcancon ; save cancon.win bits ; this is required to prevent cancon ; from corrupting can buffer access ; in-progress while this interrupt ; occurred movff canstat, tempcanstat ; save canstat register ; this is required to make sure that ; we use same canstat value rather ; than one changed by another can ; interrupt. movf tempcanstat, w ; retrieve icode bits andlw b?00001110? addwf pcl, f ; perform computed goto ; to corresponding interrupt cause bra nointerrupt ; 000 = no interrupt bra errorinterrupt ; 001 = error interrupt bra txb2interrupt ; 010 = txb2 interrupt bra txb1interrupt ; 011 = txb1 interrupt bra txb0interrupt ; 100 = txb0 interrupt bra rxb1interrupt ; 101 = rxb1 interrupt bra rxb0interrupt ; 110 = rxb0 interrupt ; 111 = wake-up on interrupt wakeupinterrupt bcf pir3, wakif ; clear the interrupt flag ; ; user code to handle wake-up procedure ; ; ; continue checking for other interrupt source or return from here ? nointerrupt ? ; pc should never vector here. user may ; place a trap such as infinite loop or pin/port ; indication to catch this error.
? 2011 microchip technology inc. ds39977d-page 399 pic18f66k80 family example 27-2: win and icode bits usage in interrupt service routine to access tx/rx buffers (continued) errorinterrupt bcf pir3, errif ; clear the interrupt flag ? ; handle error. retfie txb2interrupt bcf pir3, txb2if ; clear the interrupt flag goto accessbuffer txb1interrupt bcf pir3, txb1if ; clear the interrupt flag goto accessbuffer txb0interrupt bcf pir3, txb0if ; clear the interrupt flag goto accessbuffer rxb1interrupt bcf pir3, rxb1if ; clear the interrupt flag goto accessbuffer rxb0interrupt bcf pir3, rxb0if ; clear the interrupt flag goto accessbuffer accessbuffer ; this is either tx or rx interrupt ; copy canstat.icode bits to cancon.win bits movf tempcancon, w ; clear cancon.win bits before copying ; new ones. andlw b?11110001? ; use previously saved cancon value to ; make sure same value. movwf tempcancon ; copy masked value back to tempcancon movf tempcanstat, w ; retrieve icode bits andlw b?00001110? ; use previously saved canstat value ; to make sure same value. iorwf tempcancon ; copy icode bits to win bits. movff tempcancon, cancon ; copy the result to actual cancon ; access current buffer? ; user code ; restore cancon.win bits movf cancon, w ; preserve current non win bits andlw b?11110001? iorwf tempcancon ; restore original win bits ; do not need to restore canstat - it is read-only register. ; return from interrupt or check for another module interrupt source
pic18f66k80 family ds39977d-page 400 ? 2011 microchip technology inc. register 27-3: ecancon: en hanced can control register r/w-0 r/w-0 r/w-0 r/w-1 r/w-0 r/w-0 r/w-0 r/w-0 mdsel1 (1) mdsel0 (1) fifowm (2) ewin4 ewin3 ewin2 ewin1 ewin0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 mdsel<1:0>: mode select bits (1) 00 = legacy mode (mode 0, default) 01 = enhanced legacy mode (mode 1) 10 = enhanced fifo mode (mode 2) 11 = reserved bit 5 fifowm: fifo high water mark bit (2) 1 = will cause fifo interrupt when one receive buffer remains 0 = will cause fifo interrupt when four receive buffers remain (3) bit 4-0 ewin<4:0>: enhanced window address bits these bits map the group of 16 banked can sfrs into access bank addresses, 0f60-0f6dh. the exact group of registers to map is determined by the binary value of these bits. mode 0: unimplemented: read as ? 0 ? mode 1, 2: 00000 = acceptance filters 0, 1, 2 and brgcon2, 3 00001 = acceptance filters 3, 4, 5 and brgcon1, ciocon 00010 = acceptance filter masks, error and interrupt control 00011 = transmit buffer 0 00100 = transmit buffer 1 00101 = transmit buffer 2 00110 = acceptance filters 6, 7, 8 00111 = acceptance filters 9, 10, 11 01000 = acceptance filters 12, 13, 14 01001 = acceptance filter 15 01010 - 01110 = reserved 01111 = rxint0, rxint1 10000 = receive buffer 0 10001 = receive buffer 1 10010 = tx/rx buffer 0 10011 = tx/rx buffer 1 10100 = tx/rx buffer 2 10101 = tx/rx buffer 3 10110 = tx/rx buffer 4 10111 = tx/rx buffer 5 11000 - 11111 = reserved note 1: these bits can only be changed in configuration mode. see register 27-1 to change to configuration mode. 2: this bit is used in mode 2 only. 3: if fifo is configured to contain four or less buffers, then the fifo interrupt will trigger.
? 2011 microchip technology inc. ds39977d-page 401 pic18f66k80 family register 27-4: comstat: comm unication status register mode 0 r/c-0 r/c-0 r-0 r-0 r-0 r-0 r-0 r-0 rxb0ovfl rxb1ovfl txbo txbp rxbp txwarn rxwarn ewarn mode 1 r/c-0 r/c-0 r-0 r-0 r-0 r-0 r-0 r-0 ? rxbnovfl txb0 txbp rxbp txwarn rxwarn ewarn mode 2 r/c-0 r/c-0 r-0 r-0 r-0 r-0 r-0 r-0 fifoempty rxbnovfl txbo txbp rxbp txwarn rxwarn ewarn bit 7 bit 0 legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 mode 0: rxb0ovfl: receive buffer 0 overflow bit 1 = receive buffer 0 has overflowed 0 = receive buffer 0 has not overflowed mode 1: unimplemented: read as ? 0 ? mode 2: fifoempty : fifo not empty bit 1 = receive fifo is not empty 0 = receive fifo is empty bit 6 mode 0: rxb1ovfl: receive buffer 1 overflow bit 1 = receive buffer 1 has overflowed 0 = receive buffer 1 has not overflowed mode 1, 2: rxbnovfl: receive buffer n overflow bit 1 = receive buffer n has overflowed 0 = receive buffer n has not overflowed bit 5 txbo: transmitter bus-off bit 1 = transmit error counter > 255 0 = transmit error counter ?? 255 bit 4 txbp: transmitter bus passive bit 1 = transmit error counter > 127 0 = transmit error counter ?? 127 bit 3 rxbp: receiver bus passive bit 1 = receive error counter > 127 0 = receive error counter ?? 127 bit 2 txwarn: transmitter warning bit 1 = transmit error counter > 95 0 = transmit error counter ?? 95 bit 1 rxwarn: receiver warning bit 1 = 127 ? receive error counter > 95 0 = receive error counter ? 95 bit 0 ewarn: error warning bit this bit is a flag of the rxwarn and txwarn bits. 1 = the rxwarn or the txwarn bits are set 0 = neither the rxwarn or the txwarn bits are set
pic18f66k80 family ds39977d-page 402 ? 2011 microchip technology inc. 27.2.2 dedicated can transmit buffer registers this section describes the dedicated can transmit buffer registers and their associated control registers. register 27-5: txbncon: transmit buffer n control registers [0 ? n ? 2] mode 0 u-0 r-0 r-0 r-0 r/w-0 u-0 r/w-0 r/w-0 txbif txabt (1) txlarb (1) txerr (1) txreq (2) ?txpri1 (3) txpri0 (3) mode 1,2 r/c-0 r-0 r-0 r-0 r/w-0 u-0 r/w-0 r/w-0 txbif txabt (1) txlarb (1) txerr (1) txreq (2) ?txpri1 (3) txpri0 (3) bit 7 bit 0 legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 txbif: transmit buffer interrupt flag bit 1 = transmit buffer has completed transmission of a message and may be reloaded 0 = transmit buffer has not completed transmission of a message bit 6 txabt: transmission aborted status bit (1) 1 = message was aborted 0 = message was not aborted bit 5 txlarb: transmission lost arbitration status bit (1) 1 = message lost arbitration while being sent 0 = message did not lose arbitration while being sent bit 4 txerr: transmission error detected status bit (1) 1 = a bus error occurred while the message was being sent 0 = a bus error did not occur while the message was being sent bit 3 txreq: transmit request status bit (2) 1 = requests sending a message; clears the txabt, txlarb and txerr bits 0 = automatically cleared when the message is successfully sent bit 2 unimplemented: read as ? 0 ? bit 1-0 txpri<1:0>: transmit priority bits (3) 11 = priority level 3 (highest priority) 10 = priority level 2 01 = priority level 1 00 = priority level 0 (lowest priority) note 1: this bit is automatically cleared when txreq is set. 2: while txreq is set, transmit buffer registers remain read-only. clearing this bit in software while the bit is set will request a message abort. 3: these bits define the order in which transmit buffers will be transferred. they do not alter the can message identifier.
? 2011 microchip technology inc. ds39977d-page 403 pic18f66k80 family register 27-6: txbnsidh: transmit buffer ?n? standard identifier registers, high byte [0 ? n ? 2] r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 sid<10:3>: standard identifier bits (if exide (txbnsidl<3>) = 0 ) extended identifier bits, eid<28:21> (if exide = 1 ). register 27-7: txbnsidl: transmit buffe r ?n? standard identifier registers, low byte [0 ? n ? 2] r/w-x r/w-x r/w-x u-0 r/w-x u-0 r/w-x r/w-x sid2 sid1 sid0 ? exide ?eid17eid16 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 sid<2:0>: standard identifier bits (if exide (txbnsidl<3>) = 0 ) extended identifier bits, eid<20:18> (if exide = 1 ). bit 4 unimplemented: read as ? 0 ? bit 3 exide: extended identifier enable bit 1 = message will transmit extended id, sid<10:0> become eid<28:18> 0 = message will transmit standard id, eid<17:0> are ignored bit 2 unimplemented: read as ? 0 ? bit 1-0 eid<17:16>: extended identifier bits register 27-8: txbneidh: transmit buffer ?n? extended identifier registers, high byte [0 ? n ? 2] r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 eid<15:8>: extended identifier bits (not used when transmitting standard identifier message)
pic18f66k80 family ds39977d-page 404 ? 2011 microchip technology inc. register 27-9: txbneidl: transmit buffe r ?n? extended identifier registers, low byte [0 ? n ? 2] r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 eid<7:0>: extended identifier bits (not used when transmitting standard identifier message) register 27-10: txbndm: transmit buffer ?n? data field byte ?m? registers [0 ? n ? 2, 0 ? m ? 7] r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x txbndm7 txbndm6 txbndm5 txbndm4 t xbndm3 txbndm2 txbndm1 txbndm0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 txbndm<7:0>: transmit buffer n data field byte m bits (where 0 ?? n < 3 and 0 ?? m < 8) each transmit buffer has an array of registers. for example, transmit buffer 0 has 7 registers: txb0d0 to txb0d7.
? 2011 microchip technology inc. ds39977d-page 405 pic18f66k80 family register 27-11: txbndlc: transmit buffer ?n? data length code registers [0 ? n ? 2] u-0 r/w-x u-0 u-0 r/w-x r/w-x r/w-x r/w-x ?txrtr ? ? dlc3 dlc2 dlc1 dlc0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 txrtr: transmit remote frame transmission request bit 1 = transmitted message will have the txrtr bit set 0 = transmitted message will have the txrtr bit cleared bit 5-4 unimplemented: read as ? 0 ? bit 3-0 dlc<3:0>: data length code bits 1111 = reserved 1110 = reserved 1101 = reserved 1100 = reserved 1011 = reserved 1010 = reserved 1001 = reserved 1000 = data length = 8 bytes 0111 = data length = 7 bytes 0110 = data length = 6 bytes 0101 = data length = 5 bytes 0100 = data length = 4 bytes 0011 = data length = 3 bytes 0010 = data length = 2 bytes 0001 = data length = 1 bytes 0000 = data length = 0 bytes register 27-12: txerrcnt: transm it error count register r-0 r-0 r-0 r-0 r-0 r-0 r-0 r-0 tec7 tec6 tec5 tec4 tec3 tec2 tec1 tec0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 tec<7:0>: transmit error counter bits this register contains a value which is derived from the rate at which errors occur. when the error count overflows, the bus-off state occurs. when the bus has 128 occurrences of 11 consecutive recessive bits, the counter value is cleared.
pic18f66k80 family ds39977d-page 406 ? 2011 microchip technology inc. example 27-3: transmitting a can message using banked method ; need to transmit standard identifier message 123h using txb0 buffer. ; to successfully transmit, can module must be either in normal or loopback mode. ; txb0 buffer is not in access bank. and since we want banked method, we need to make sure ; that correct bank is selected. banksel txb0con ; one banksel in beginning will make sure that we are ; in correct bank for rest of the buffer access. ; now load transmit data into txb0 buffer. movlw my_data_byte1 ; load first data byte into buffer movwf txb0d0 ; compiler will automatically set ?banked? bit ; load rest of data bytes - up to 8 bytes into txb0 buffer. ... ; load message identifier movlw 60h ; load sid2:sid0, exide = 0 movwf txb0sidl movlw 24h ; load sid10:sid3 movwf txb0sidh ; no need to load txb0eidl:txb0eidh, as we are transmitting standard identifier message only. ; now that all data bytes are loaded, mark it for transmission. movlw b?00001000? ; normal priority; request transmission movwf txb0con ; if required, wait for message to get transmitted btfsc txb0con, txreq ; is it transmitted? bra $-2 ; no. continue to wait... ; message is transmitted.
? 2011 microchip technology inc. ds39977d-page 407 pic18f66k80 family example 27-4: transmitting a can message using win bits ; need to transmit standard identifier message 123h using txb0 buffer. ; to successfully transmit, can module must be either in normal or loopback mode. ; txb0 buffer is not in access bank. use win bits to map it to rxb0 area. movf cancon, w ; win bits are in lower 4 bits only. read cancon ; register to preserve all other bits. if operation ; mode is already known, there is no need to preserve ; other bits. andlw b?11110000? ; clear win bits. iorlw b?00001000? ; select transmit buffer 0 movwf cancon ; apply the changes. ; now txb0 is mapped in place of rxb0. all future access to rxb0 registers will actually ; yield txb0 register values. ; load transmit data into txb0 buffer. movlw my_data_byte1 ; load first data byte into buffer movwf rxb0d0 ; access txb0d0 via rxb0d0 address. ; load rest of the data bytes - up to 8 bytes into ?txb0? buffer using rxb0 registers. ... ; load message identifier movlw 60h ; load sid2:sid0, exide = 0 movwf rxb0sidl movlw 24h ; load sid10:sid3 movwf rxb0sidh ; no need to load rxb0eidl:rxb0eidh, as we are transmitting standard identifier message only. ; now that all data bytes are loaded, mark it for transmission. movlw b?00001000? ; normal priority; request transmission movwf rxb0con ; if required, wait for message to get transmitted btfsc rxb0con, txreq ; is it transmitted? bra $-2 ; no. continue to wait... ; message is transmitted. ; if required, reset the win bits to default state.
pic18f66k80 family ds39977d-page 408 ? 2011 microchip technology inc. 27.2.3 dedicated can receive buffer registers this section shows the dedicated can receive buffer registers with their associated control registers. register 27-13: rxb0con: rece ive buffer 0 control register mode 0 r/c-0 r/w-0 r/w-0 u-0 r-0 r/w-0 r-0 r-0 rxful (1) rxm1 rxm0 ? rxrtrro rxb0dben jtoff (2) filhit0 mode 1,2 r/c-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 rxful (1) rxm1 rtrro filhitf4 filhit3 filhit2 filhit1 filhit0 bit 7 bit 0 legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 rxful: receive full status bit (1) 1 = receive buffer contains a received message 0 = receive buffer is open to receive a new message bit 6,6-5 mode 0: rxm<1:0>: receive buffer mode bit 1 (combines with rxm0 to form rxm<1:0> bits, see bit 5) 11 = receive all messages (including those with errors); filter criteria is ignored 10 = receive only valid messages with extended identifier; exiden in rxfnsidl must be ? 1 ? 01 = receive only valid messages with standard identifier; exiden in rxfnsidl must be ? 0 ? 00 = receive all valid messages as per the exiden bit in the rxfnsidl register mode 1, 2: rxm1 : receive buffer mode bit 1 1 = receive all messages (including those with errors); acceptance filters are ignored 0 = receive all valid messages as per acceptance filters bit 5 mode 0: rxm0: receive buffer mode bit 0 (combines with rxm1 to form rxm<1:0>bits, see bit 6) mode 1, 2: rtrro: remote transmission request bit for received message (read-only) 1 = a remote transmission request is received 0 = a remote transmission request is not received bit 4 mode 0: unimplemented: read as ? 0 ? mode 1, 2: filhit<4:0>: filter hit bit 4 this bit combines with other bits to form filter acceptance bits<4:0>. bit 3 mode 0: rxrtrro: remote transmission request bit for received message (read-only) 1 = a remote transmission request is received 0 = a remote transmission request is not received mode 1, 2: filhit<4:0>: filter hit bit 3 this bit combines with other bits to form filter acceptance bits<4:0>. note 1: this bit is set by the can module upon receiving a message and must be cleared by software after the buffer is read. as long as rxful is set, no new message will be loaded and the buffer will be considered full. after clearing the rxful flag, the pir5 bit, rxb0if, can be cleared. if rxb0if is cleared, but rxful is not cleared, then rxb0if is set again. 2: this bit allows the same filter jump table for both rxb0con and rxb1con.
? 2011 microchip technology inc. ds39977d-page 409 pic18f66k80 family bit 2 mode 0: rb0dben: receive buffer 0 double-buffer enable bit 1 = receive buffer 0 overflow will write to receive buffer 1 0 = no receive buffer 0 overflow to receive buffer 1 mode 1, 2: filhit<4:0>: filter hit bit 2 this bit combines with other bits to form filter acceptance bits<4:0>. bit 1 mode 0: jtoff: jump table offset bit (read-only copy of rxb0dben) (2) 1 = allows jump table offset between 6 and 7 0 = allows jump table offset between 1 and 0 mode 1, 2: filhit<4:0>: filter hit bit 1 this bit combines with other bits to form filter acceptance bits<4:0>. bit 0 mode 0: filhit0: filter hit bit 0 this bit indicates which acceptance filter enabled the message reception into receive buffer 0. 1 = acceptance filter 1 (rxf1) 0 = acceptance filter 0 (rxf0) mode 1, 2: filhit<4:0>: filter hit bit 0 this bit, in combination with filhit<4:1>, indicates which acceptance filter enabled the message reception into this receive buffer. 01111 = acceptance filter 15 (rxf15) 01110 = acceptance filter 14 (rxf14) ... 00000 = acceptance filter 0 (rxf0) register 27-13: rxb0con: receive buffer 0 control register (continued) note 1: this bit is set by the can module upon receiving a message and must be cleared by software after the buffer is read. as long as rxful is set, no new message will be loaded and the buffer will be considered full. after clearing the rxful flag, the pir5 bit, rxb0if, can be cleared. if rxb0if is cleared, but rxful is not cleared, then rxb0if is set again. 2: this bit allows the same filter jump table for both rxb0con and rxb1con.
pic18f66k80 family ds39977d-page 410 ? 2011 microchip technology inc. register 27-14: rxb1con: recei ve buffer 1 control register mode 0 r/c-0 r/w-0 r/w-0 u-0 r-0 r/w-0 r-0 r-0 rxful (1) rxm1 rxm0 ? rxrtrro filhit2 filhit1 filhit0 mode 1,2 r/c-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 rxful (1) rxm1 rtrro filhit4 filhit3 filhit2 filhit1 filhit0 bit 7 bit 0 legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 rxful: receive full status bit (1) 1 = receive buffer contains a received message 0 = receive buffer is open to receive a new message bit 6-5, 6 mode 0: rxm<1:0>: receive buffer mode bit 1 (combines with rxm0 to form rxm<1:0> bits, see bit 5) 11 = receive all messages (including those with errors); filter criteria is ignored 10 = receive only valid messages with extended identifier; exiden in rxfnsidl must be ? 1 ? 01 = receive only valid messages with standard identifier, exiden in rxfnsidl must be ? 0 ? 00 = receive all valid messages as per exiden bit in rxfnsidl register mode 1, 2: rxm1: receive buffer mode bit 1 = receive all messages (including those with errors); acceptance filters are ignored 0 = receive all valid messages as per acceptance filters bit 5 mode 0: rxm<1:0>: receive buffer mode bit 0 (combines with rxm1 to form rxm<1:0> bits, see bit 6) mode 1, 2: rtrro: remote transmission request bit for received message (read-only) 1 = a remote transmission request is received 0 = a remote transmission request is not received bit 4 mode 0 : filhit2 4: filter hit bit 4 m ode 1, 2: filhit<4:0>: filter hit bit 4 this bit combines with other bits to form the filter acceptance bits<4:0>. bit 3 mode 0: rxrtrro: remote transmission request bit for received message (read-only) 1 = a remote transmission request is received 0 = a remote transmission request is not received mode 1, 2: filhit<4:0>: filter hit bit 3 this bit combines with other bits to form the filter acceptance bits<4:0>. note 1: this bit is set by the can module upon receiving a message and must be cleared by software after the buffer is read. as long as rxful is set, no new message will be loaded and the buffer will be considered full.
? 2011 microchip technology inc. ds39977d-page 411 pic18f66k80 family bit 2-0 mode 0: filhit<2:0>: filter hit bits these bits indicate which acceptance filter enabled the last message reception into receive buffer 1. 111 = reserved 110 = reserved 101 = acceptance filter 5 (rxf5) 100 = acceptance filter 4 (rxf4) 011 = acceptance filter 3 (rxf3) 010 = acceptance filter 2 (rxf2) 001 = acceptance filter 1 (rxf1), only possible when rxb0dben bit is set 000 = acceptance filter 0 (rxf0), only possible when rxb0dben bit is set mode 1, 2: filhit<4:0>: filter hit bits<2:0> these bits, in combination with filhit<4:3>, indicate which acceptance filter enabled the message reception into this receive buffer. 01111 = acceptance filter 15 (rxf15) 01110 = acceptance filter 14 (rxf14) ... 00000 = acceptance filter 0 (rxf0) register 27-14: rxb1con: receive buffe r 1 control register (continued) note 1: this bit is set by the can module upon receiving a message and must be cleared by software after the buffer is read. as long as rxful is set, no new message will be loaded and the buffer will be considered full. register 27-15: rxbnsidh: receive buffer ?n? standard identifier registers, high byte [0 ? n ? 1] r-x r-x r-x r-x r-x r-x r-x r-x sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 sid<10:3>: standard identifier bits (if exid (rxbnsidl<3>) = 0 ) extended identifier bits, eid<28:21> (if exid = 1 ).
pic18f66k80 family ds39977d-page 412 ? 2011 microchip technology inc. register 27-16: rxbnsidl: receive buffer ?n? standard identifier registers, low byte [0 ? n ? 1] r-x r-x r-x r-x r-x u-0 r-x r-x sid2 sid1 sid0 srr exid ?eid17eid16 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 sid<2:0>: standard identifier bits (if exid = 0 ) extended identifier bits, eid<20:18> (if exid = 1 ). bit 4 srr: substitute remote request bit bit 3 exid: extended identifier bit 1 = received message is an extended data frame, sid<10:0> are eid<28:18> 0 = received message is a standard data frame bit 2 unimplemented: read as ? 0 ? bit 1-0 eid<17:16>: extended identifier bits register 27-17: rxbneidh: receive buffer ?n? extended identifier registers, high byte [0 ? n ? 1] r-x r-x r-x r-x r-x r-x r-x r-x eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 eid<15:8>: extended identifier bits register 27-18: rxbneidl: receive buffe r ?n? extended identifier registers, low byte [0 ? n ? 1] r-x r-x r-x r-x r-x r-x r-x r-x eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 eid<7:0>: extended identifier bits
? 2011 microchip technology inc. ds39977d-page 413 pic18f66k80 family register 27-19: rxbndlc: receive buffer ?n? data length code registers [0 ? n ? 1] u-0 r-x r-x r-x r-x r-x r-x r-x ? rxrtr rb1 r0 dlc3 dlc2 dlc1 dlc0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 rxrtr: receiver remote transmission request bit 1 = remote transfer request 0 = no remote transfer request bit 5 rb1: reserved bit 1 reserved by can spec and read as ? 0 ?. bit 4 rb0: reserved bit 0 reserved by can spec and read as ? 0 ?. bit 3-0 dlc<3:0>: data length code bits 1111 = invalid 1110 = invalid 1101 = invalid 1100 = invalid 1011 = invalid 1010 = invalid 1001 = invalid 1000 = data length = 8 bytes 0111 = data length = 7 bytes 0110 = data length = 6 bytes 0101 = data length = 5 bytes 0100 = data length = 4 bytes 0011 = data length = 3 bytes 0010 = data length = 2 bytes 0001 = data length = 1 byte 0000 = data length = 0 bytes register 27-20: rxbndm: receive buffer ?n? data field byte ?m? registers [0 ? n ? 1, 0 ? m ? 7] r-x r-x r-x r-x r-x r-x r-x r-x rxbndm7 rxbndm6 rxbndm5 rxbndm4 r xbndm3 rxbndm2 rxbndm1 rxbndm0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 rxbndm<7:0>: receive buffer n data field byte m bits (where 0 ?? n < 1 and 0 < m < 7) each receive buffer has an array of registers. for example, receive buffer 0 has 8 registers: rxb0d0 to rxb0d7.
pic18f66k80 family ds39977d-page 414 ? 2011 microchip technology inc. example 27-5: reading a can message register 27-21: rxerrcnt: rece ive error count register r-0 r-0 r-0 r-0 r-0 r-0 r-0 r-0 rec7 rec6 rec5 rec4 rec3 rec2 rec1 rec0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 rec<7:0>: receive error counter bits this register contains the receive error value as defined by the can specifications. when rxerrcnt > 127, the module will go into an error-passive state. rxerrcnt does not have the ability to put the module in ?bus-off? state. ; need to read a pending message from rxb0 buffer. ; to receive any message, filter, mask and rxm1:rxm0 bits in rxb0con registers must be ; programmed correctly. ; ; make sure that there is a message pending in rxb0. btfss rxb0con, rxful ; does rxb0 contain a message? bra nomessage ; no. handle this situation... ; we have verified that a message is pending in rxb0 buffer. ; if this buffer can receive both standard or extended identifier messages, ; identify type of message received. btfss rxb0sidl, exid ; is this extended identifier? bra standardmessage ; no. this is standard identifier message. ; yes. this is extended identifier message. ; read all 29-bits of extended identifier message. ... ; now read all data bytes movff rxb0do, my_data_byte1 ... ; once entire message is read, mark the rxb0 that it is read and no longer full. bcf rxb0con, rxful ; this will allow can module to load new messages ; into this buffer. ...
? 2011 microchip technology inc. ds39977d-page 415 pic18f66k80 family 27.2.3.1 programmable tx/rx and auto-rtr buffers the ecan module contains 6 message buffers that can be programmed as transmit or receive buffers. any of these buffers can also be programmed to automatically handle rtr messages. note: these registers are not used in mode 0. register 27-22: bncon: tx/rx buffer ?n? control registers in receive mode [0 ? n ? 5, txnen (bsel0) = 0 ] (1) r/w-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 rxful (2) rxm1 rxrtrro filhit4 filhit3 filhit2 filhit1 filhit0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 rxful: receive full status bit (2) 1 = receive buffer contains a received message 0 = receive buffer is open to receive a new message bit 6 rxm1: receive buffer mode bit 1 = receive all messages including partial and invalid (acceptance filters are ignored) 0 = receive all valid messages as per acceptance filters bit 5 rxrtrro: read-only remote transmission request for received message bit 1 = received message is a remote transmission request 0 = received message is not a remote transmission request bit 4-0 filhit<4:0>: filter hit bits these bits indicate which acceptance filter enabled the last message reception into this buffer. 01111 = acceptance filter 15 (rxf15) 01110 = acceptance filter 14 (rxf14) ... 00001 = acceptance filter 1 (rxf1) 00000 = acceptance filter 0 (rxf0) note 1: these registers are available in mode 1 and 2 only. 2: this bit is set by the can module upon receiving a message and must be cleared by software after the buffer is read. as long as rxful is set, no new message will be loaded and the buffer will be considered full.
pic18f66k80 family ds39977d-page 416 ? 2011 microchip technology inc. register 27-23: bncon: tx/rx buffer ?n? control registers in transmit mode [0 ? n ? 5, txnen (bsel0) = 1 ] (1) r/w-0 r-0 r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 txbif (3) txabt (3) txlarb (3) txerr (3) txreq (2,4) rtren txpri1 (5) txpri0 (5) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 txbif: transmit buffer interrupt flag bit (3) 1 = a message was successfully transmitted 0 = no message was transmitted bit 6 txabt: transmission aborted status bit (3) 1 = message was aborted 0 = message was not aborted bit 5 txlarb: transmission lost arbitration status bit (3) 1 = message lost arbitration while being sent 0 = message did not lose arbitration while being sent bit 4 txerr: transmission error detected status bit (3) 1 = a bus error occurred while the message was being sent 0 = a bus error did not occur while the message was being sent bit 3 txreq: transmit request status bit (2,4) 1 = requests sending a message; clears the txabt, txlarb and txerr bits 0 = automatically cleared when the message is successfully sent bit 2 rtren: automatic remote transmission request enable bit 1 = when a remote transmission request is received, txreq will be automatically set 0 = when a remote transmission request is received, txreq will be unaffected bit 1-0 txpri<1:0>: transmit priority bits (5) 11 = priority level 3 (highest priority) 10 = priority level 2 01 = priority level 1 00 = priority level 0 (lowest priority) note 1: these registers are available in mode 1 and 2 only. 2: clearing this bit in software while the bit is set will request a message abort. 3: this bit is automatically cleared when txreq is set. 4: while txreq is set or a transmission is in progress, transmit buffer registers remain read-only. 5: these bits set the order in which the transmit buffer register will be transferred. they do not alter the can message identifier.
? 2011 microchip technology inc. ds39977d-page 417 pic18f66k80 family register 27-24: bnsidh: tx/rx buffer ?n? standard identifier registers, high byte in receive mode [0 ? n ? 5, txnen (bsel0) = 0 ] (1) r-x r-x r-x r-x r-x r-x r-x r-x sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 sid<10:3>: standard identifier bits (if exide (bnsidl<3>) = 0 ) extended identifier bits, eid<28:21> (if exide = 1 ). note 1: these registers are available in mode 1 and 2 only. register 27-25: bnsidh: tx/rx buffer ?n? standard identifier registers, high byte in transmit mode [0 ? n ? 5, txnen (bsel0) = 1 ] (1) r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 sid<10:3>: standard identifier bits (if exide (bnsidl<3>) = 0 ) extended identifier bits, eid<28:21> (if exide = 1 ). note 1: these registers are available in mode 1 and 2 only.
pic18f66k80 family ds39977d-page 418 ? 2011 microchip technology inc. register 27-26: bnsidl: tx/rx buffer ?n? standard identifier registers, low byte in receive mode [0 ? n ? 5, txnen (bsel0) = 0 ] (1) r-x r-x r-x r-x r-x u-0 r-x r-x sid2 sid1 sid0 srr exide ?eid17eid16 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 sid<2:0>: standard identifier bits (if exid = 0 ) extended identifier bits, eid<20:18> (if exid = 1 ). bit 4 srr: substitute remote transmission request bit this bit is always ? 1 ? when exid = 1 or equal to the value of rxrtrro (bncon<5>) when exid = 0 . bit 3 exide: extended identifier enable bit 1 = received message is an extended identifier frame (sid<10:0> are eid<28:18>) 0 = received message is a standard identifier frame bit 2 unimplemented: read as ? 0 ? bit 1-0 eid<17:16>: extended identifier bits note 1: these registers are available in mode 1 and 2 only. register 27-27: bnsidl: tx/rx buffer ?n? standard identifier registers, low byte in receive mode [0 ? n ? 5, txnen (bsel0) = 1 ] (1) r/w-x r/w-x r/w-x u-0 r/w-x u-0 r/w-x r/w-x sid2 sid1 sid0 ? exide ?eid17eid16 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 sid<2:0>: standard identifier bits (if exide = 0 ) extended identifier bits, eid<20:18> (if exide = 1 ). bit 4 unimplemented: read as ? 0 ? bit 3 exide: extended identifier enable bit 1 = received message is an extended identifier frame (sid<10:0> are eid<28:18>) 0 = received message is a standard identifier frame bit 2 unimplemented: read as ? 0 ? bit 1-0 eid<17:16>: extended identifier bits note 1: these registers are available in mode 1 and 2 only.
? 2011 microchip technology inc. ds39977d-page 419 pic18f66k80 family register 27-28: bneidh: tx/rx buffer ?n? extended identifier registers, high byte in receive mode [0 ? n ? 5, txnen (bsel0) = 0 ] (1) r-x r-x r-x r-x r-x r-x r-x r-x eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 eid<15:8>: extended identifier bits note 1: these registers are available in mode 1 and 2 only. register 27-29: bneidh: tx/rx buffer ?n? extended identifier registers, high byte in transmit mode [0 ? n ? 5, txnen (bsel0) = 1 ] (1) r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 eid<15:8>: extended identifier bits note 1: these registers are available in mode 1 and 2 only. register 27-30: bneidl: tx/rx buffer ?n? extended identifier registers, low byte in receive mode [0 ? n ? 5, txnen (bsel) = 0 ] (1) r-x r-x r-x r-x r-x r-x r-x r-x eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 eid<7:0>: extended identifier bits note 1: these registers are available in mode 1 and 2 only.
pic18f66k80 family ds39977d-page 420 ? 2011 microchip technology inc. register 27-31: bneidl: tx/rx buffer ?n? extended identifier registers, low byte in receive mode [0 ? n ? 5, txnen (bsel) = 1 ] (1) r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid7 eid6 eid5 feid4 eid3 eid2 eid1 eid0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 eid<7:0>: extended identifier bits note 1: these registers are available in mode 1 and 2 only. register 27-32: bndm: tx/rx buffer ?n? data field byte ?m? registers in receive mode [0 ? n ? 5, 0 ? m ? 7, txnen (bsel) = 0 ] (1) r-x r-x r-x r-x r-x r-x r-x r-x bndm7 bndm6 bndm5 bndm4 bndm3 bndm2 bndm1 bndm0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 bndm<7:0>: receive buffer n data field byte m bits (where 0 ?? n < 3 and 0 < m < 8) each receive buffer has an array of registers. for example, receive buffer 0 has 7 registers: b0d0 to b0d7. note 1: these registers are available in mode 1 and 2 only. register 27-33: bndm: tx/rx buffer ?n? data field byte ?m? registers in transmit mode [0 ? n ? 5, 0 ? m ? 7, txnen (bsel) = 1 ] (1) r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x bndm7 bndm6 bndm5 bndm4 bndm3 bndm2 bndm1 bndm0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 bndm<7:0>: transmit buffer n data field byte m bits (where 0 ?? n < 3 and 0 < m < 8) each transmit buffer has an array of registers. for example, transmit buffer 0 has 7 registers: txb0d0 to txb0d7. note 1: these registers are available in mode 1 and 2 only.
? 2011 microchip technology inc. ds39977d-page 421 pic18f66k80 family register 27-34: bndlc: tx/rx buffer ?n? data length code registers in receive mode [0 ? n ? 5, txnen (bsel) = 0 ] (1) u-0 r-x r-x r-x r-x r-x r-x r-x ? rxrtr rb1 rb0 dlc3 dlc2 dlc1 dlc0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 rxrtr: receiver remote transmission request bit 1 = this is a remote transmission request 0 = this is not a remote transmission request bit 5 rb1: reserved bit 1 reserved by can spec and read as ? 0 ?. bit 4 rb0: reserved bit 0 reserved by can spec and read as ? 0 ?. bit 3-0 dlc<3:0>: data length code bits 1111 = reserved 1110 = reserved 1101 = reserved 1100 = reserved 1011 = reserved 1010 = reserved 1001 = reserved 1000 = data length = 8 bytes 0111 = data length = 7 bytes 0110 = data length = 6 bytes 0101 = data length = 5 bytes 0100 = data length = 4 bytes 0011 = data length = 3 bytes 0010 = data length = 2 bytes 0001 = data length = 1 byte 0000 = data length = 0 bytes note 1: these registers are available in mode 1 and 2 only.
pic18f66k80 family ds39977d-page 422 ? 2011 microchip technology inc. register 27-35: bndlc: tx/rx buffer ?n? data length code registers in transmit mode [0 ? n ? 5, txnen (bsel) = 1 ] (1) u-0 r/w-x u-0 u-0 r/w-x r/w-x r/w-x r/w-x ?txrtr ? ? dlc3 dlc2 dlc1 dlc0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 txrtr: transmitter remote transmission request bit 1 = transmitted message will have the rtr bit set 0 = transmitted message will have the rtr bit cleared bit 5-4 unimplemented: read as ? 0 ? bit 3-0 dlc<3:0>: data length code bits 1111 - 1001 = reserved 1000 = data length = 8 bytes 0111 = data length = 7 bytes 0110 = data length = 6 bytes 0101 = data length = 5 bytes 0100 = data length = 4 bytes 0011 = data length = 3 bytes 0010 = data length = 2 bytes 0001 = data length = 1 byte 0000 = data length = 0 bytes note 1: these registers are available in mode 1 and 2 only. register 27-36: bsel0: buffer select register 0 (1) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 u-0 b5txen b4txen b3txen b2txen b1txen b0txen ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-2 b<5:0>txen: buffer 5 to buffer 0 transmit enable bits 1 = buffer is configured in transmit mode 0 = buffer is configured in receive mode bit 1-0 unimplemented: read as ? 0 ? note 1: these registers are available in mode 1 and 2 only.
? 2011 microchip technology inc. ds39977d-page 423 pic18f66k80 family 27.2.3.2 message acceptance filters and masks this section describes the message acceptance filters and masks for the can receive buffers. register 27-37: rxfnsidh: receive acceptance filter ?n? standard identifier filter registers, high byte [0 ? n ? 15] (1) r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 sid<10:3>: standard identifier filter bits (if exiden = 0 ) extended identifier filter bits, eid<28:21> (if exiden = 1 ). note 1: registers, rxf6sidh:rxf15sidh, are available in mode 1 and 2 only. register 27-38: rxfnsidl: receive acceptance filter ?n? standard identifier filter registers, low byte [0 ? n ? 15] (1) r/w-x r/w-x r/w-x u-0 r/w-x u-0 r/w-x r/w-x sid2 sid1 sid0 ? exiden (2) ?eid17eid16 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 sid<2:0>: standard identifier filter bits (if exiden = 0 ) extended identifier filter bits, eid<20:18> (if exiden = 1 ). bit 4 unimplemented: read as ? 0 ? bit 3 exiden: extended identifier filter enable bit (2) 1 = filter will only accept extended id messages 0 = filter will only accept standard id messages bit 2 unimplemented: read as ? 0 ? bit 1-0 eid<17:16>: extended identifier filter bits note 1: registers, rxf6sidl:rxf15sidl, are available in mode 1 and 2 only. 2: in mode 0, this bit must be set/cleared as required, irrespective of corresponding mask register value.
pic18f66k80 family ds39977d-page 424 ? 2011 microchip technology inc. register 27-39: rxfneidh: receive acceptance filter ?n? extended identifier registers, high byte [0 ? n ? 15] (1) r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 eid<15:8>: extended identifier filter bits note 1: registers, rxf6eidh:rxf15eidh, are available in mode 1 and 2 only. register 27-40: rxfneidl: receive acceptance filter ?n? extended identifier registers, low byte [0 ? n ? 15] (1) r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 eid<7:0>: extended identifier filter bits note 1: registers, rxf6eidl:rxf15eidl, are available in mode 1 and 2 only. register 27-41: rxmnsidh: receive acceptance mask ?n? standard identifier mask registers, high byte [0 ? n ? 1] r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x sid10 sid9 sid8 sid7 sid6 sid5 sid4 sid3 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 sid<10:3>: standard identifier mask bits or extended identifier mask bits (eid<28:21>)
? 2011 microchip technology inc. ds39977d-page 425 pic18f66k80 family register 27-42: rxmnsidl: receive acceptance mask ?n? standard identifier mask registers, low byte [0 ? n ? 1] r/w-x r/w-x r/w-x u-0 r/w-0 u-0 r/w-x r/w-x sid2 sid1 sid0 ? exiden (1) ?eid17eid16 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 sid<2:0>: standard identifier mask bits or extended identifier mask bits (eid<20:18>) bit 4 unimplemented: read as ? 0 ? bit 3 mode 0: unimplemented: read as ? 0 ? mode 1, 2 : exiden: extended identifier filter enable mask bit (1) 1 = messages selected by the exiden bit in rxfnsidl will be accepted 0 = both standard and extended identifier messages will be accepted bit 2 unimplemented: read as ? 0 ? bit 1-0 eid<17:16>: extended identifier mask bits note 1: this bit is available in mode 1 and 2 only. register 27-43: rxmneidh: receive accept ance mask ?n? extended identifier mask registers, high byte [0 ? n ? 1] r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid15 eid14 eid13 eid12 eid11 eid10 eid9 eid8 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 eid<15:8>: extended identifier mask bits register 27-44: rxmneidl: receive acceptance mask ?n? extended identifier mask registers, low byte [0 ? n ? 1] r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x eid7 eid6 eid5 eid4 eid3 eid2 eid1 eid0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 eid<7:0>: extended identifier mask bits
pic18f66k80 family ds39977d-page 426 ? 2011 microchip technology inc. register 27-45: rxfconn: receive filter control register ?n? [0 ? n ? 1] (1) rxfcon0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 rxf7en rxf6en rxf5en rxf4en rxf3en rxf2en rxf1en rxf0en rxfcon1 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 rxf15en rxf14en rxf13en rxf12en rxf11en rxf10en rxf9en rxf8en bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 rxf<7:0>en: receive filter n enable bits 0 = filter is disabled 1 = filter is enabled note 1: this register is available in mode 1 and 2 only. note: register 27-46 through register 27-51 are writable in configuration mode only. register 27-46: sdflc: standard data by tes filter length count register (1) u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? flc4 flc3 flc2 flc1 flc0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 flc<4:0>: filter length count bits mode 0: not used; forced to ? 00000 ?. 00000 - 10010 = 0 18 bits are available for standard data byte filter. actual number of bits used depends on the dlc<3:0> bits (rxbndlc<3:0> or bndlc<3:0> if configured as rx buffer) of the message being received. if dlc<3:0> = 0000 no bits will be compared with incoming data bits. if dlc<3:0> = 0001 up to 8 data bits of rxfneid<7:0>, as determined by flc<2:0>, will be com- pared with the corresponding number of data bits of the incoming message. if dlc<3:0> = 0010 up to 16 data bits of rxfneid<15:0>, as determined by flc<3:0>, will be compared with the corresponding number of data bits of the incoming message. if dlc<3:0> = 0011 up to 18 data bits of rxfneid<17:0>, as determined by flc<4:0>, will be compared with the corresponding number of data bits of the incoming message. note 1: this register is available in mode 1 and 2 only.
? 2011 microchip technology inc. ds39977d-page 427 pic18f66k80 family register 27-47: rxfbconn: receive filter buffer control register ?n? (1) rxfbcon0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 f1bp_3 f1bp_2 f1bp_1 f1bp_0 f 0bp_3 f0bp_2 f0bp_1 f0bp_0 rxfbcon1 r/w-0 r/w-0 r/w-0 r/w-1 r/w-0 r/w-0 r/w-0 r/w-1 f3bp_3 f3bp_2 f3bp_1 f3bp_0 f 2bp_3 f2bp_2 f2bp_1 f2bp_0 rxfbcon2 r/w-0 r/w-0 r/w-0 r/w-1 r/w-0 r/w-0 r/w-0 r/w-1 f5bp_3 f5bp_2 f5bp_1 f5bp_0 f 4bp_3 f4bp_2 f4bp_1 f4bp_0 rxfbcon3 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 f7bp_3 f7bp_2 f7bp_1 f7bp_0 f 6bp_3 f6bp_2 f6bp_1 f6bp_0 rxfbcon4 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 f9bp_3 f9bp_2 f9bp_1 f9bp_0 f 8bp_3 f8bp_2 f8bp_1 f8bp_0 rxfbcon5 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 f11bp_3 f11bp_2 f11bp_1 f11bp_0 f10bp_3 f10bp_2 f10bp_1 f10bp_0 rxfbcon6 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 f13bp_3 f13bp_2 f13bp_1 f13bp_0 f12bp_3 f12bp_2 f12bp_1 f12bp_0 rxfbcon7 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 f15bp_3 f15bp_2 f15bp_1 f15bp_0 f14bp_3 f14bp_2 f14bp_1 f14bp_0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 f<15:2>bp_<3:0>: filter n buffer pointer nibble bits 0000 = filter n is associated with rxb0 0001 = filter n is associated with rxb1 0010 = filter n is associated with b0 0011 = filter n is associated with b1 ... 0111 = filter n is associated with b5 1111-1000 = reserved note 1: this register is available in mode 1 and 2 only.
pic18f66k80 family ds39977d-page 428 ? 2011 microchip technology inc. register 27-48: msel0: mask select register 0 (1) r/w-0 r/w-1 r/w-0 r/w-1 r/w-0 r/w-0 r/w-0 r/w-0 fil3_1 fil3_0 fil2_1 fil2_0 fil1_1 fil1_0 fil0_1 fil0_0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 fil3_<1:0>: filter 3 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 5-4 fil2_<1:0>: filter 2 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 3-2 fil1_<1:0>: filter 1 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 1-0 fil0_<1:0>: filter 0 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 note 1: this register is available in mode 1 and 2 only.
? 2011 microchip technology inc. ds39977d-page 429 pic18f66k80 family register 27-49: msel1: mask select register 1 (1) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-1 r/w-0 r/w-1 fil7_1 fil7_0 fil6_1 fil6_0 fil5_1 fil5_0 fil4_1 fil4_0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 fil7_<1:0>: filter 7 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 5-4 fil6_<1:0>: filter 6 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 3-2 fil5_<1:0>: filter 5 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 1-0 fil4_<1:0>: filter 4 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 note 1: this register is available in mode 1 and 2 only.
pic18f66k80 family ds39977d-page 430 ? 2011 microchip technology inc. register 27-50: msel2: mask select register 2 (1) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 fil11_1 fil11_0 fil10_1 fil10_0 fil9_1 fil9_0 fil8_1 fil8_0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 fil11_<1:0>: filter 11 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 5-4 fil10_<1:0>: filter 10 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 3-2 fil9_<1:0>: filter 9 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 1-0 fil8_<1:0>: filter 8 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 note 1: this register is available in mode 1 and 2 only.
? 2011 microchip technology inc. ds39977d-page 431 pic18f66k80 family register 27-51: msel3: mask select register 3 (1) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 fil15_1 fil15_0 fil14_1 fil14_0 fil13_1 fil13_0 fil12_1 fil12_0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 fil15_<1:0>: filter 15 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 5-4 fil14_<1:0>: filter 14 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 3-2 fil13_<1:0>: filter 13 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 bit 1-0 fil12_<1:0>: filter 12 select bits 1 and 0 11 = no mask 10 = filter 15 01 = acceptance mask 1 00 = acceptance mask 0 note 1: this register is available in mode 1 and 2 only.
pic18f66k80 family ds39977d-page 432 ? 2011 microchip technology inc. 27.2.4 can baud rate registers this section describes the can baud rate registers. note: these registers are writable in configuration mode only. register 27-52: brgcon1: bau d rate control register 1 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 sjw1 sjw0 brp5 brp4 brp3 brp2 brp1 brp0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 sjw<1:0>: synchronized jump width bits 11 = synchronization jump width time = 4 x t q 10 = synchronization jump width time = 3 x t q 01 = synchronization jump width time = 2 x t q 00 = synchronization jump width time = 1 x t q bit 5-0 brp<5:0>: baud rate prescaler bits 111111 = t q = (2 x 64)/f osc 111110 = t q = (2 x 63)/f osc : : 000001 = t q = (2 x 2)/f osc 000000 = t q = (2 x 1)/f osc
? 2011 microchip technology inc. ds39977d-page 433 pic18f66k80 family register 27-53: brgcon2: bau d rate control register 2 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 seg2phts sam seg1ph2 seg1ph1 seg1ph0 prseg2 prseg1 prseg0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 seg2phts: phase segment 2 time select bit 1 = freely programmable 0 = maximum of pheg1 or information processing time (ipt), whichever is greater bit 6 sam: sample of the can bus line bit 1 = bus line is sampled three times prior to the sample point 0 = bus line is sampled once at the sample point bit 5-3 seg1ph<2:0>: phase segment 1 bits 111 = phase segment 1 time = 8 x t q 110 = phase segment 1 time = 7 x t q 101 = phase segment 1 time = 6 x t q 100 = phase segment 1 time = 5 x t q 011 = phase segment 1 time = 4 x t q 010 = phase segment 1 time = 3 x t q 001 = phase segment 1 time = 2 x t q 000 = phase segment 1 time = 1 x t q bit 2-0 prseg<2:0>: propagation time select bits 111 = propagation time = 8 x t q 110 = propagation time = 7 x t q 101 = propagation time = 6 x t q 100 = propagation time = 5 x t q 011 = propagation time = 4 x t q 010 = propagation time = 3 x t q 001 = propagation time = 2 x t q 000 = propagation time = 1 x t q
pic18f66k80 family ds39977d-page 434 ? 2011 microchip technology inc. register 27-54: brgcon3: bau d rate control register 3 r/w-0 r/w-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 wakdis wakfil ? ? ? seg2ph2 (1) seg2ph1 (1) seg2ph0 (1) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 wakdis: wake-up disable bit 1 = disable can bus activity wake-up feature 0 = enable can bus activity wake-up feature bit 6 wakfil: selects can bus line filter for wake-up bit 1 = use can bus line filter for wake-up 0 = can bus line filter is not used for wake-up bit 5-3 unimplemented: read as ? 0 ? bit 2-0 seg2ph<2:0>: phase segment 2 time select bits (1) 111 = phase segment 2 time = 8 x t q 110 = phase segment 2 time = 7 x t q 101 = phase segment 2 time = 6 x t q 100 = phase segment 2 time = 5 x t q 011 = phase segment 2 time = 4 x t q 010 = phase segment 2 time = 3 x t q 001 = phase segment 2 time = 2 x t q 000 = phase segment 2 time = 1 x t q note 1: ignored if seg2phts bit (brgcon2<7>) is ? 0 ?.
? 2011 microchip technology inc. ds39977d-page 435 pic18f66k80 family 27.2.5 can module i/o control register this register controls the operation of the can module?s i/o pins in relation to the rest of the microcontroller. register 27-55: ciocon: can i/o control register r/w-0 r/w-0 r/w-0 r/w-0 u-0 u-0 u-0 r/w-0 tx2src tx2en endrhi (1) cancap ? ? ? clksel bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 tx2src: cantx2 pin data source bit 1 = cantx2 pin will output the can clock 0 = cantx2 pin will output cantx bit 6 tx2en: cantx pin enable bit 1 = cantx2 pin will output cantx or can clock as selected by the tx2src bit 0 = cantx2 pin will have digital i/o function bit 5 endrhi: enable drive high bit (1) 1 = cantx pin will drive v dd when recessive 0 = cantx pin will be tri-state when recessive bit 4 cancap: can message receive capture enable bit 1 = enable can capture; can message receive signal replaces input on rc2/ccp1 0 = disable can capture; rc2/ccp1 input to ccp1 module bit 3-1 unimplemented: read as ? 0 ? bit 0 clksel: can clock source selection bit 1 = use the oscillator as the source of the can system clock 0 = use the pll as the source of the can system clock note 1: always set this bit when using a differential bus to avoid signal crosstalk in cantx from other nearby pins.
pic18f66k80 family ds39977d-page 436 ? 2011 microchip technology inc. 27.2.6 can interrupt registers the registers in this section are the same as described in section 10.0 ?interrupts? . they are duplicated here for convenience. register 27-56: pir5: peripheral in terrupt request (flag) register 5 mode 0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x irxif wakif errif txb2if txb1if (1) txb0if (1) rxb1if rxb0if mode 1,2 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x irxif wakif errif txbnif txb1if (1) txb0if (1) rxbnif fifowmif bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 irxif: can bus error message received interrupt flag bit 1 = an invalid message has occurred on the can bus 0 = no invalid message on the can bus bit 6 wakif: can bus activity wake-up interrupt flag bit 1 = activity on the can bus has occurred 0 = no activity on the can bus bit 5 errif: can module error interrupt flag bit 1 = an error has occurred in the can module (multiple sources; refer to section 27.15.6 ?error interrupt? ) 0 = no can module errors bit 4 when can is in mode 0: txb2if: can transmit buffer 2 interrupt flag bit 1 = transmit buffer 2 has completed transmission of a message and may be reloaded 0 = transmit buffer 2 has not completed transmission of a message when can is in mode 1 or 2: txbnif: any transmit buffer interrupt flag bit 1 = one or more transmit buffers have completed transmission of a message and may be reloaded 0 = no transmit buffer is ready for reload bit 3 txb1if: can transmit buffer 1 interrupt flag bit (1) 1 = transmit buffer 1 has completed transmission of a message and may be reloaded 0 = transmit buffer 1 has not completed transmission of a message bit 2 txb0if: can transmit buffer 0 interrupt flag bit (1) 1 = transmit buffer 0 has completed transmission of a message and may be reloaded 0 = transmit buffer 0 has not completed transmission of a message bit 1 when can is in mode 0: rxb1if: can receive buffer 1 interrupt flag bit 1 = receive buffer 1 has received a new message 0 = receive buffer 1 has not received a new message when can is in mode 1 or 2: rxbnif: any receive buffer interrupt flag bit 1 = one or more receive buffers has received a new message 0 = no receive buffer has received a new message bit 0 when can is in mode 0: rxb0if: can receive buffer 0 interrupt flag bit 1 = receive buffer 0 has received a new message 0 = receive buffer 0 has not received a new message when can is in mode 1: unimplemented: read as ? 0 ? when can is in mode 2: fifowmif: fifo watermark interrupt flag bit 1 = fifo high watermark is reached 0 = fifo high watermark is not reached note 1: in can mode 1 and 2, these bits are forced to ? 0 ?.
? 2011 microchip technology inc. ds39977d-page 437 pic18f66k80 family register 27-57: pie5: peripheral interrupt enable register 5 mode 0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x irxie wakie errie txb2ie txb1ie (1) txb0ie (1) rxb1ie rxb0ie mode 1 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x irxie wakie errie txbnie txb1ie (1) txb0ie (1) rxbnie fifowmie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 irxie: can bus error message received interrupt enable bit 1 = enable invalid message received interrupt 0 = disable invalid message received interrupt bit 6 wakie: can bus activity wake-up interrupt enable bit 1 = enable bus activity wake-up interrupt 0 = disable bus activity wake-up interrupt bit 5 errie: can bus error interrupt enable bit 1 = enable can module error interrupt 0 = disable can module error interrupt bit 4 when can is in mode 0: txb2ie: can transmit buffer 2 interrupt enable bit 1 = enable transmit buffer 2 interrupt 0 = disable transmit buffer 2 interrupt when can is in mode 1 or 2: txbnie: can transmit buffer interrupts enable bit 1 = enable transmit buffer interrupt; individual interrupt is enabled by txbie and bie0 0 = disable all transmit buffer interrupts bit 3 txb1ie: can transmit buffer 1 interrupt enable bit (1) 1 = enable transmit buffer 1 interrupt 0 = disable transmit buffer 1 interrupt bit 2 txb0ie: can transmit buffer 0 interrupt enable bit (1) 1 = enable transmit buffer 0 interrupt 0 = disable transmit buffer 0 interrupt bit 1 when can is in mode 0: rxb1ie: can receive buffer 1 interrupt enable bit 1 = enable receive buffer 1 interrupt 0 = disable receive buffer 1 interrupt when can is in mode 1 or 2: rxbnie: can receive buffer interrupts enable bit 1 = enable receive buffer interrupt; individual interrupt is enabled by bie0 0 = disable all receive buffer interrupts bit 0 when can is in mode 0: rxb0ie: can receive buffer 0 interrupt enable bit 1 = enable receive buffer 0 interrupt 0 = disable receive buffer 0 interrupt when can is in mode 1: unimplemented: read as ? 0 ? when can is in mode 2: fifowmie: fifo watermark interrupt enable bit 1 = enable fifo watermark interrupt 0 = disable fifo watermark interrupt note 1: in can mode 1 and 2, these bits are forced to ? 0 ?.
pic18f66k80 family ds39977d-page 438 ? 2011 microchip technology inc. register 27-58: ipr5: peripheral interrupt priority register 5 mode 0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x irxip wakip errip txb2ip txb1ip (1) txb0ip (1) rxb1ip rxb0ip mode 1,2 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x irxip wakip errip txbnip txb1ip (1) txb0ip (1) rxbnip fifowmip bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 irxip: can bus error message received interrupt priority bi t 1 = high priority 0 = low priority bit 6 wakip: can bus activity wake-up interrupt priority bit 1 = high priority 0 = low priority bit 5 errip: can module error interrupt priority bit 1 = high priority 0 = low priority bit 4 when can is in mode 0: txb2ip: can transmit buffer 2 interrupt priority bit 1 = high priority 0 = low priority when can is in mode 1 or 2: txbnip: can transmit buffer interrupt priority bit 1 = high priority 0 = low priority bit 3 txb1ip: can transmit buffer 1 interrupt priority bit (1) 1 = high priority 0 = low priority bit 2 txb0ip: can transmit buffer 0 interrupt priority bit (1) 1 = high priority 0 = low priority bit 1 when can is in mode 0: rxb1ip: can receive buffer 1 interrupt priority bit 1 = high priority 0 = low priority when can is in mode 1 or 2: rxbnip: can receive buffer interrupts priority bit 1 = high priority 0 = low priority bit 0 when can is in mode 0: rxb0ip: can receive buffer 0 interrupt priority bit 1 = high priority 0 = low priority when can is in mode 1: unimplemented: read as ? 0 ? when can is in mode 2: fifowmip: fifo watermark interrupt priority bit 1 = high priority 0 = low priority note 1: in can mode 1 and 2, these bits are forced to ? 0 ?.
? 2011 microchip technology inc. ds39977d-page 439 pic18f66k80 family register 27-59: txbie: transmit buffers interrupt enable register (1) u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 u-0 u-0 ? ? ? txb2ie (2) txb1ie (2) txb0ie (2) ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-2 txb2ie:txb0ie: transmit buffer 2-0 interrupt enable bits (2) 1 = transmit buffer interrupt is enabled 0 = transmit buffer interrupt is disabled bit 1-0 unimplemented: read as ? 0 ? note 1: this register is available in mode 1 and 2 only. 2: txbnie in pie5 register must be set to get an interrupt. register 27-60: bie0: buffer interrupt enable register 0 (1) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 b5ie (2) b4ie (2) b3ie (2) b2ie (2) b1ie (2) b0ie (2) rxb1ie (2) rxb0ie (2) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-2 b<5:0>ie: programmable transmit/receive buffer 5-0 interrupt enable bits (2) 1 = interrupt is enabled 0 = interrupt is disabled bit 1-0 rxb<1:0>ie: dedicated receive buffer 1-0 interrupt enable bits (2) 1 = interrupt is enabled 0 = interrupt is disabled note 1: this register is available in mode 1 and 2 only. 2: either txbnie or rxbnie in the pie5 register must be set to get an interrupt.
pic18f66k80 family ds39977d-page 440 ? 2011 microchip technology inc. 27.3 can modes of operation the pic18f66k80 family has six main modes of operation: ? configuration mode ? disable/sleep mode ? normal operation mode ? listen only mode ? loopback mode ? error recognition mode all modes, except error recognition, are requested by setting the reqop bits (cancon<7:5>). error recog- nition mode is requested through the rxm bits of the receive buffer register(s). entry into a mode is acknowledged by monitoring the opmode bits. when changing modes, the mode will not actually change until all pending message transmissions are complete. because of this, the user must verify that the device has actually changed into the requested mode before further operations are executed. 27.3.1 configuration mode the can module has to be initialized before the activation. this is only possible if the module is in the configuration mode. the configuration mode is requested by setting the reqop2 bit. only when the status bit, opmode2, has a high level can the initial- ization be performed. afterwards, the configuration registers, the acceptance mask registers and the acceptance filter registers can be written. the module is activated by setting the reqop control bits to zero. the module will protect the user from accidentally violating the can protocol through programming errors. all registers which control the configuration of the module can not be modified while the module is on- line. the can module will not be allowed to enter the configuration mode while a transmission or reception is taking place. the configuration mode serves as a lock to protect the following registers: ? configuration registers ? functional mode selection registers ? bit timing registers ? identifier acceptance filter registers ? identifier acceptance mask registers ? filter and mask control registers ? mask selection registers in the configuration mode, the module will not transmit or receive. the error counters are cleared and the inter- rupt flags remain unchanged. the programmer will have access to configuration registers that are access restricted in other modes. i/o pins will revert to normal i/o functions . 27.3.2 disable/sleep mode in disable/sleep mode, the module will not transmit or receive. the module has the ability to set the wakif bit due to bus activity; however, any pending interrupts will remain and the error counters will retain their value. if the reqop<2:0> bits are set to ? 001 ?, the module will enter the module disable/sleep mode. this mode is similar to disabling other peripheral modules by turning off the module enables. this causes the module internal clock to stop unless the module is active (i.e., receiving or transmitting a message). if the module is active, the module will wait for 11 recessive bits on the can bus, detect that condition as an idle bus, then accept the module disable/sleep command. opmode<2:0> = 001 indicates whether the module successfully went into the module disable/sleep mode. the wakif interrupt is the only module interrupt that is still active in the disable/sleep mode. if the wakdis is cleared and wakie is set, the processor will receive an interrupt whenever the module detects recessive to dominant transition. on wake-up, the module will auto- matically be set to the previous mode of operation. for example, if the module was switched from normal to disable/sleep mode on bus activity wake-up, the module will automatically enter into normal mode and the first message that caused the module to wake-up is lost. the module will not generate any error frame. firmware logic must detect this condition and make sure that retransmission is requested. if the processor receives a wake-up interrupt while it is sleeping, more than one message may get lost. the actual number of messages lost would depend on the processor oscillator start-up time and incoming message bit rate. the txcan pin will stay in the recessive state while the module is in disable/sleep mode. 27.3.3 normal mode this is the standard operating mode of the pic18f66k80 family devices. in this mode, the device actively monitors all bus messages and generates acknowledge bits, error frames, etc. this is also the only mode in which the pic18f66k80 family devices will transmit messages over the can bus.
? 2011 microchip technology inc. ds39977d-page 441 pic18f66k80 family 27.3.4 listen only mode listen only mode provides a means for the pic18f66k80 family devices to receive all messages, including messages with errors. this mode can be used for bus monitor applications or for detecting the baud rate in ?hot plugging? situations. for auto-baud detection, it is necessary that there are at least two other nodes which are communicating with each other. the baud rate can be detected empirically by testing different values until valid messages are received. the listen only mode is a silent mode, meaning no mes- sages will be transmitted while in this state, including error flags or acknowledge signals. the filters and masks can be used to allow only particular messages to be loaded into the receive registers or the filter masks can be set to all zeros to allow a message with any identifier to pass. the error counters are reset and deactivated in this state. the listen only mode is acti- vated by setting the mode request bits in the cancon register. 27.3.5 loopback mode this mode will allow internal transmission of messages from the transmit buffers to the receive buffers without actually transmitting messages on the can bus. this mode can be used in system development and testing. in this mode, the ack bit is ignored and the device will allow incoming messages from itself, just as if they were coming from another node. the loopback mode is a silent mode, meaning no messages will be trans- mitted while in this state, including error flags or acknowledge signals. the txcan pin will revert to port i/o while the device is in this mode. the filters and masks can be used to allow only particular messages to be loaded into the receive registers. the masks can be set to all zeros to provide a mode that accepts all messages. the loopback mode is activated by setting the mode request bits in the cancon register. 27.3.6 error recognition mode the module can be set to ignore all errors and receive any message. in functional mode 0, the error recogni- tion mode is activated by setting the rxm<1:0> bits in the rxbncon registers to ? 11 ?. in this mode, the data which is in the message assembly buffer until the error time, is copied in the receive buffer and can be read via the cpu interface. 27.4 can module functional modes in addition to can modes of operation, the ecan mod- ule offers a total of 3 functional modes. each of these modes are identified as mode 0, mode 1 and mode 2. 27.4.1 mode 0 ? legacy mode mode 0 is designed to be fully compatible with can modules used in pic18cxx8 and pic18fxx8 devices. this is the default mode of operation on all reset con- ditions. as a result, module code written for the pic18xx8 can module may be used on the ecan module without any code changes. the following is the list of resources available in mode 0: ? three transmit buffers: txb0, txb1 and txb2 ? two receive buffers: rxb0 and rxb1 ? two acceptance masks, one for each receive buffer: rxm0, rxm1 ? six acceptance filters, 2 for rxb0 and 4 for rxb1: rxf0, rxf1, rxf2, rxf3, rxf4, rxf5 27.4.2 mode 1 ? enhanced legacy mode mode 1 is similar to mode 0, with the exception that more resources are available in mode 1. there are 16 acceptance filters and two acceptance mask regis- ters. acceptance filter 15 can be used as either an acceptance filter or an acceptance mask register. in addition to three transmit and two receive buffers, there are six more message buffers. one or more of these additional buffers can be programmed as transmit or receive buffers. these additional buffers can also be programmed to automatically handle rtr messages. fourteen of sixteen acceptance filter registers can be dynamically associated to any receive buffer and acceptance mask register. one can use this capability to associate more than one filter to any one buffer. when a receive buffer is programmed to use standard identifier messages, part of the full acceptance filter reg- ister can be used as a data byte filter. the length of the data byte filter is programmable from 0 to 18 bits. this functionality simplifies implementation of high-level protocols, such as the devicenet? protocol. the following is the list of resources available in mode 1: ? three transmit buffers: txb0, txb1 and txb2 ? two receive buffers: rxb0 and rxb1 ? six buffers programmable as tx or rx: b0-b5 ? automatic rtr handling on b0-b5 ? sixteen dynamically assigned acceptance filters: rxf0-rxf15 ? two dedicated acceptance mask registers; rxf15 programmable as third mask: rxm0-rxm1, rxf15 ? programmable data filter on standard identifier messages: sdflc
pic18f66k80 family ds39977d-page 442 ? 2011 microchip technology inc. 27.4.3 mode 2 ? enhanced fifo mode in mode 2, two or more receive buffers are used to form the receive fifo (first in, first out) buffer. there is no one-to-one relationship between the receive buffer and acceptance filter registers. any filter that is enabled and linked to any fifo receive buffer can generate acceptance and cause fifo to be updated. fifo length is user-programmable, from 2-8 buffers deep. fifo length is determined by the very first programmable buffer that is configured as a transmit buffer. for example, if buffer 2 (b2) is programmed as a transmit buffer, fifo consists of rxb0, rxb1, b0 and b1, creating a fifo length of 4. if all programmable buffers are configured as receive buffers, fifo will have the maximum length of 8. the following is the list of resources available in mode 2: ? three transmit buffers: txb0, txb1 and txb2 ? two receive buffers: rxb0 and rxb1 ? six buffers programmable as tx or rx; receive buffers form fifo: b0-b5 ? automatic rtr handling on b0-b5 ? sixteen acceptance filters: rxf0-rxf15 ? two dedicated acceptance mask registers; rxf15 programmable as third mask: rxm0-rxm1, rxf15 ? programmable data filter on standard identifier messages: sdflc, useful for devicenet protocol 27.5 can message buffers 27.5.1 dedicated transmit buffers the pic18f66k80 family devices implement three dedicated transmit buffers ? txb0, txb1 and txb2. each of these buffers occupies 14 bytes of sram and are mapped into the sfr memory map. these are the only transmit buffers available in mode 0. mode 1 and 2 may access these and other additional buffers. each transmit buffer contains one control register (txbncon), four identifier registers (txbnsidl, txbnsidh, txbneidl, txbneidh), one data length count register (txbndlc) and eight data byte registers (txbndm). 27.5.2 dedicated receive buffers the pic18f66k80 family devices implement two dedi- cated receive buffers: rxb0 and rxb1. each of these buffers occupies 14 bytes of sram and are mapped into sfr memory map. these are the only receive buf- fers available in mode 0. mode 1 and 2 may access these and other additional buffers. each receive buffer contains one control register (rxbncon), four identifier registers (rxbnsidl, rxbnsidh, rxbneidl, rxbneidh), one data length count register (rxbndlc) and eight data byte registers (rxbndm). there is also a separate message assembly buffer (mab) which acts as an additional receive buffer. mab is always committed to receiving the next message from the bus and is not directly accessible to user firm- ware. the mab assembles all incoming messages one by one. a message is transferred to appropriate receive buffers only if the corresponding acceptance filter criteria is met. 27.5.3 programmable transmit/ receive buffers the ecan module implements six new buffers: b0-b5. these buffers are individually programmable as either transmit or receive buffers. these buffers are available only in mode 1 and 2. as with dedicated transmit and receive buffers, each of these programmable buffers occupies 14 bytes of sram and are mapped into sfr memory map. each buffer contains one control register (bncon), four identifier registers (bnsidl, bnsidh, bneidl, bneidh), one data length count register (bndlc) and eight data byte registers (bndm). each of these registers contains two sets of control bits. depending on whether the buffer is configured as transmit or receive, one would use the corresponding control bit set. by default, all buffers are configured as receive buffers. each buffer can be individually configured as a transmit or receive buffer by setting the corresponding txenn bit in the bsel0 register. when configured as transmit buffers, user firmware may access transmit buffers in any order similar to accessing dedicated transmit buffers. in receive configuration with mode 1 enabled, user firmware may also access receive buffers in any order required. but in mode 2, all receive buffers are combined to form a single fifo. actual fifo length is programmable by user firmware. access to fifo must be done through the fifo pointer bits (fp<4:0>) in the cancon register. it must be noted that there is no hardware protection against out of order fifo reads.
? 2011 microchip technology inc. ds39977d-page 443 pic18f66k80 family 27.5.4 programmable auto-rtr buffers in mode 1 and 2, any of six programmable transmit/ receive buffers may be programmed to automatically respond to predefined rtr messages without user firmware intervention. automatic rtr handling is enabled by setting the tx2en bit in the bsel0 register and the rtren bit in the bncon register. after this setup, when an rtr request is received, the txreq bit is automatically set and the current buffer content is automatically queued for transmission as a rtr response. as with all transmit buffers, once the txreq bit is set, buffer registers become read-only and any writes to them will be ignored. the following outlines the steps required to automatically handle rtr messages: 1. set buffer to transmit mode by setting the txnen bit to ? 1 ? in the bsel0 register. 2. at least one acceptance filter must be associ- ated with this buffer and preloaded with the expected rtr identifier. 3. bit, rtren in the bncon register, must be set to ? 1 ? . 4. buffer must be preloaded with the data to be sent as a rtr response. normally, user firmware will keep buffer data registers up to date. if firmware attempts to update the buffer while an automatic rtr response is in the process of transmission, all writes to buffers are ignored. 27.6 can message transmission 27.6.1 initiating transmission for the mcu to have write access to the message buf- fer, the txreq bit must be clear, indicating that the message buffer is clear of any pending message to be transmitted. at a minimum, the sidh, sidl and dlc registers must be loaded. if data bytes are present in the message, the data registers must also be loaded. if the message is to use extended identifiers, the eidh:eidl registers must also be loaded and the exide bit set. to initiate message transmission, the txreq bit must be set for each buffer to be transmitted. when txreq is set, the txabt, txlarb and txerr bits will be cleared. to successfully complete the transmission, there must be at least one node with matching baud rate on the network. setting the txreq bit does not initiate a message transmission; it merely flags a message buffer as ready for transmission. transmission will start when the device detects that the bus is available. the device will then begin transmission of the highest priority message that is ready. when the transmission has completed successfully, the txreq bit will be cleared, the txbnif bit will be set and an interrupt will be generated if the txbnie bit is set. if the message transmission fails, the txreq will remain set, indicating that the message is still pending for trans- mission and one of the following condition flags will be set. if the message started to transmit but encountered an error condition, the txerr and the irxif bits will be set and an interrupt will be generated. if the message lost arbitration, the txlarb bit will be set. 27.6.2 aborting transmission the mcu can request to abort a message by clearing the txreq bit associated with the corresponding mes- sage buffer (txbncon<3> or bncon<3>). setting the abat bit (cancon<4>) will request an abort of all pending messages. if the message has not yet started transmission, or if the mess age started but is interrupted by loss of arbitration or an error, the abort will be pro- cessed. the abort is indicated when the module sets the txabt bit for the corresponding buffer (txbncon<6> or bncon<6>). if the message has started to transmit, it will attempt to transmit the current message fully. if the current message is transmitted fully and is not lost to arbitration or an error, the txabt bit will not be set because the message was transmitted successfully. likewise, if a message is being transmitted during an abort request and the message is lost to arbitration or an error, the message will not be retransmitted and the txabt bit will be set, indicating that the message was successfully aborted. once an abort is requested by setting the abat or txabt bits, it cannot be cleared to cancel the abort request. only can module hardware or a por condition can clear it.
pic18f66k80 family ds39977d-page 444 ? 2011 microchip technology inc. 27.6.3 transmit priority transmit priority is a prioritization within the pic18f66k80 family devices of the pending transmitta- ble messages. this is independent from, and not related to, any prioritization implicit in the message arbitration scheme built into the can protocol. prior to sending the start-of-frame (sof), the priority of all buf- fers that are queued for transmission is compared. the transmit buffer with the highest priority will be sent first. if two buffers have the same priority setting, the buffer with the highest buffer number will be sent first. there are four levels of transmit priority. if the txp bits for a particular message buffer are set to ? 11 ?, that buffer has the highest possible priority. if the txp bits for a partic- ular message buffer are set to ? 00 ?, that buffer has the lowest possible priority. figure 27-2: transmit buffers txreq txb0 txabt txlarb txerr txb0if message message queue control transmit byte sequencer txreq txb1 txabt txlarb txerr txb1if message txreq txb2 txabt txlarb txerr txb2if message message txb2if txreq txabt txlarb txerr txb3-txb8
? 2011 microchip technology inc. ds39977d-page 445 pic18f66k80 family 27.7 message reception 27.7.1 receiving a message of all receive buffers, the mab is always committed to receiving the next message from the bus. the mcu can access one buffer while the other buffer is available for message reception or holding a previously received message. when a message is moved into either of the receive buffers, the associated rxful bit is set. this bit must be cleared by the mcu when it has completed process- ing the message in the buffer in order to allow a new message to be received into the buffer. this bit provides a positive lockout to ensure that the firmware has finished with the message before the module attempts to load a new message into the receive buffer. if the receive interrupt is enabled, an interrupt will be generated to indicate that a valid message has been received. once a message is loaded into any matching buffer, user firmware may determine exactly what filter caused this reception by checking the filter hit bits in the rxbncon or bncon registers. in mode 0, filhit<2:0> of rxbncon serve as filter hit bits. in mode 1 and 2, filhit<4:0> bits of bncon serve as filter hit bits. the same registers also indicate whether the current message is an rtr frame or not. a received message is considered a standard identifier message if the exid/exide bit in the rxbnsidl or the bnsidl register is cleared. conversely, a set exid bit indicates an extended identifier message. if the received message is a standard identifier message, user firmware needs to read the sidl and sidh regis- ters. in the case of an extended identifier message, firmware should read the sidl, sidh, eidl and eidh registers. if the rxbndlc or bndlc register contain non-zero data count, user firmware should also read the corresponding number of data bytes by accessing the rxbndm or the bndm registers. when a received message is an rtr, and if the current buffer is not con- figured for automatic rtr handling, user firmware must take appropriate action and respond manually. each receive buffer contains rxm bits to set special receive modes. in mode 0, rxm<1:0> bits in rxbncon define a total of four receive modes. in mode 1 and 2, rxm1 bit, in combination with the exid mask and filter bit, define the same four receive modes. normally, these bits are set to ? 00 ? to enable reception of all valid messages as determined by the appropriate acceptance filters. in this case, the determination of whether or not to receive standard or extended messages is determined by the exide bit in the accep- tance filter register. in mode 0, if the rxm bits are set to ? 01 ? or ? 10 ?, the receiver will accept only messages with standard or extended identifiers, respectively. if an acceptance filter has the exide bit set, such that it does not correspond with the rxm mode, that accep- tance filter is rendered useless. in mode 1 and 2, setting exid in the sidl mask register will ensure that only standard or extended identifiers are received. these two modes of rxm bits can be used in systems where it is known that only standard or extended mes- sages will be on the bus. if the rxm bits are set to ? 11 ? (rxm1 = 1 in mode 1 and 2), the buffer will receive all messages regardless of the values of the acceptance filters. also, if a message has an error before the end of frame, that portion of the message assembled in the mab before the error frame will be loaded into the buf- fer. this mode may serve as a valuable debugging tool for a given can network. it should not be used in an actual system environment as the actual system will always have some bus errors and all nodes on the bus are expected to ignore them. in mode 1 and 2, when a programmable buffer is configured as a transmit buffer and one or more accep- tance filters are associated with it, all incoming messages matching this acceptance filter criteria will be discarded. to avoid this scenario, user firmware must make sure that there are no acceptance filters associated with a buffer configured as a transmit buffer. 27.7.2 receive priority when in mode 0, rxb0 is the higher priority buffer and has two message acceptance filters associated with it. rxb1 is the lower priority buffer and has four acceptance filters associated with it. the lower number of acceptance filters makes the match on rxb0 more restrictive and implies a higher priority for that buffer. additionally, the rxb0con register can be configured such that if rxb0 contains a valid message and another valid message is received, an overflow error will not occur and the new message will be moved into rxb1 regardless of the acceptance criteria of rxb1. there are also two programmable acceptance filter masks available, one for each receive buffer (see section 27.5 ?can message buffers? ). in mode 1 and 2, there are a total of 16 acceptance filters available and each can be dynamically assigned to any of the receive buffers. a buffer with a lower number has higher priority. given this, if an incoming message matches with two or more receive buffer acceptance criteria, the buffer with the lower number will be loaded with that message. note: the entire contents of the mab are moved into the receive buffer once a message is accepted. this means that regardless of the type of identifier (standard or extended) and the number of data bytes received, the entire receive buffer is over- written with the mab contents. therefore, the contents of all registers in the buffer must be assumed to have been modified when any message is received.
pic18f66k80 family ds39977d-page 446 ? 2011 microchip technology inc. 27.7.3 enhanced fifo mode when configured for mode 2, two of the dedicated receive buffers in combination with one or more pro- grammable transmit/receive buffers, are used to create a maximum of an 8 buffers deep fifo buffer. in this mode, there is no direct correlation between filters and receive buffer registers. any filter that has been enabled can generate an acceptance. when a message has been accepted, it is stored in the next available receive buffer register and an internal write pointer is incremented. the fifo can be a maximum of 8 buffers deep. the entire fifo must consist of con- tiguous receive buffers. the fifo head begins at rxb0 buffer and its tail spans toward b5. the maxi- mum length of the fifo is limited by the presence or absence of the first transmit buffer starting from b0. if a buffer is configured as a transmit buffer, the fifo length is reduced accordingly. for instance, if b3 is configured as a transmit buffer, the actual fifo will consist of rxb0, rxb1, b0, b1 and b2, a total of 5 buf- fers. if b0 is configured as a transmit buffer, the fifo length will be 2. if none of the programmable buffers are configured as a transmit buffer, the fifo will be 8 buffers deep. a system that requires more transmit buffers should try to locate transmit buffers at the very end of b0-b5 buffers to maximize available fifo length. when a message is received in fifo mode, the inter- rupt flag code bits (eicode<4:0>) in the canstat register will have a value of ? 10000 ?, indicating the fifo has received a message. fifo pointer bits, fp<3:0> in the cancon register, point to the buffer that contains data not yet read. the fifo pointer bits, in this sense, serve as the fifo read pointer. the user should use the fp bits and read corresponding buffer data. when receive data is no longer needed, the rxful bit in the current buffer must be cleared, causing fp<3:0> to be updated by the module. to determine whether fifo is empty or not, the user may use the fp<3:0> bits to access the rxful bit in the current buffer. if rxful is cleared, the fifo is con- sidered to be empty. if it is set, the fifo may contain one or more messages. in mode 2, the module also provides a bit called fifo high water mark (fifowm) in the ecancon register. this bit can be used to cause an interrupt whenever the fifo contains only one or four empty buffers. the fifo high water mark interrupt can serve as an early warning to a full fifo condition. 27.7.4 time-stamping the can module can be programmed to generate a time-stamp for every message that is received. when enabled, the module generates a capture signal for ccp1, which in turn captures the value of either timer1 or timer3. this value can be used as the message time-stamp. to use the time-stamp capability, the cancap bit (ciocon<4>) must be set. this replaces the capture input for ccp1 with the signal generated from the can module. in addition, ccp1con<3:0> must be set to ? 0011 ? to enable the ccp special event trigger for can events. 27.8 message acceptance filters and masks the message acceptance filters and masks are used to determine if a message in the message assembly buf- fer should be loaded into any of the receive buffers. once a valid message has been received into the mab, the identifier fields of the message are compared to the filter values. if there is a match, that message will be loaded into the appropriate receive buffer. the filter masks are used to determine which bits in the identifier are examined with the filters. a truth table is shown below in table 27-1 that indicates how each bit in the identifier is compared to the masks and filters to determine if a message should be loaded into a receive buffer. the mask essentially determines which bits to apply the acceptance filters to. if any mask bit is set to a zero, then that bit will automatically be accepted regardless of the filter bit. table 27-1: filter/mask truth table in mode 0, acceptance filters, rxf0 and rxf1, and filter mask, rxm0, are associated with rxb0. filters, rxf2, rxf3, rxf4 and rxf5, and mask, rxm1, are associated with rxb1. mask bit n filter bit n message identifier bit n001 accept or reject bit n 0x x accept 10 0 accept 10 1 reject 11 0 reject 11 1 accept legend: x = don?t care
? 2011 microchip technology inc. ds39977d-page 447 pic18f66k80 family in mode 1 and 2, there are an additional 10 acceptance filters, rxf6-rxf15, creating a total of 16 available filters. rxf15 can be used either as an acceptance filter or acceptance mask register. each of these acceptance filters can be individually enabled or disabled by setting or clearing the rxfenn bit in the rxfconn register. any of these 16 acceptance filters can be dynamically associated with any of the receive buffers. actual association is made by setting the appropriate bits in the rxfbconn register. each rxfbconn register contains a nibble for each filter. this nibble can be used to associate a specific filter to any of available receive buffers. user firmware may associate more than one filter to any one specific receive buffer. in addition to dynamic filter to buffer association, in mode 1 and 2, each filter can also be dynamically asso- ciated to available acceptance mask registers. the filn_m bits in the mseln register can be used to link a specific acceptance filter to an acceptance mask reg- ister. as with filter to buffer association, one can also associate more than one mask to a specific acceptance filter. when a filter matches and a message is loaded into the receive buffer, the filter number that enabled the message reception is loaded into the filhit bit(s). in mode 0 for rxb1, the rxb1con register contains the filhit<2:0> bits. they are coded as follows: ? 101 = acceptance filter 5 (rxf5) ? 100 = acceptance filter 4 (rxf4) ? 011 = acceptance filter 3 (rxf3) ? 010 = acceptance filter 2 (rxf2) ? 001 = acceptance filter 1 (rxf1) ? 000 = acceptance filter 0 (rxf0) the coding of the rxb0dben bit enables these three bits to be used similarly to the filhit bits and to distin- guish a hit on filter, rxf0 and rxf1, in either rxb0 or after a rollover into rxb1. ? 111 = acceptance filter 1 (rxf1) ? 110 = acceptance filter 0 (rxf0) ? 001 = acceptance filter 1 (rxf1) ? 000 = acceptance filter 0 (rxf0) if the rxb0dben bit is clear, there are six codes corresponding to the six filters. if the rxb0dben bit is set, there are six codes corresponding to the six filters, plus two additional codes corresponding to rxf0 and rxf1 filters, that rollover into rxb1. in mode 1 and 2, each buffer control register contains 5 bits of filter hit bits (filhit<4:0>). a binary value of ? 0 ? indicates a hit from rxf0 and 15 indicates rxf15. if more than one acceptance filter matches, the filhit bits will encode the binary value of the lowest num- bered filter that matched. in other words, if filter rxf2 and filter rxf4 match, filhit will be loaded with the value for rxf2. this essentially prioritizes the acceptance filters with a lower number filter having higher priority. messages are compared to filters in ascending order of filter number. the mask and filter registers can only be modified when the pic18f66k80 family devices are in configuration mode. figure 27-3: message acceptance mask and filter operation note: ? 000 ? and ? 001 ? can only occur if the rxb0dben bit is set in the rxb0con register, allowing rxb0 messages to rollover into rxb1. acceptance filter register acceptance mask register rxrqst message assembly buffer rxfn 0 rxfn 1 rxfn n rxmn 0 rxmn 1 rxmn n identifier
pic18f66k80 family ds39977d-page 448 ? 2011 microchip technology inc. 27.9 baud rate setting all nodes on a given can bus must have the same nominal bit rate. the can protocol uses non-return- to-zero (nrz) coding which does not encode a clock within the data stream. therefore, the receive clock must be recovered by the receiving nodes and synchronized to the transmitter?s clock. as oscillators and transmission time may vary from node to node, the receiver must have some type of phase lock loop (pll) synchronized to data transmis- sion edges to synchronize and maintain the receiver clock. since the data is nrz coded, it is necessary to include bit stuffing to ensure that an edge occurs at least every six bit times to maintain the digital phase lock loop (dpll) synchronization. the bit timing of the pic18f66k80 family is imple- mented using a dpll that is configured to synchronize to the incoming data and provides the nominal timing for the transmitted data. the dpll breaks each bit time into multiple segments made up of minimal periods of time called the time quanta (t q ). bus timing functions executed within the bit time frame, such as synchronization to the local oscillator, network transmission delay compensation and sample point positioning, are defined by the programmable bit timing logic of the dpll. all devices on the can bus must use the same bit rate. however, all devices are not required to have the same master oscillator clock frequency. for the different clock frequencies of the individual devices, the bit rate has to be adjusted by appropriately setting the baud rate prescaler and number of time quanta in each segment. the ?nominal bit rate? is the number of bits transmitted per second, assuming an ideal transmitter with an ideal oscillator, in the absence of resynchronization. the nominal bit rate is defined to be a maximum of 1 mb/s. the ?nominal bit time? is defined as: equation 27-1: the nominal bit time can be thought of as being divided into separate, non-overlapping time segments. these segments ( figure 27-4 ) include: ? synchronization segment (sync_seg) ? propagation time segment (prop_seg) ? phase buffer segment 1 (phase_seg1) ? phase buffer segment 2 (phase_seg2) the time segments (and thus, the nominal bit time) are, in turn, made up of integer units of time called time quanta or t q (see figure 27-4 ). by definition, the nominal bit time is programmable from a minimum of 8 t q to a maximum of 25 t q . also by definition, the minimum nominal bit time is 1 ? s, corresponding to a maximum 1 mb/s rate. the actual duration is given by the following relationship. equation 27-2: the time quantum is a fixed unit derived from the oscillator period. it is also defined by the programmable baud rate prescaler, with integer values from 1 to 64, in addition to a fixed divide-by-two for clock generation. mathematically, this is: equation 27-3: where f osc is the clock frequency, t osc is the corresponding oscillator period and brp is an integer (0 through 63) represented by the binary values of brgcon1<5:0>. the equation above refers to the effective clock frequency used by the microcontroller. if, for example, a 10 mhz crystal in hs mode is used, then f osc = 10 mhz and t osc = 100 ns. if the same 10 mhz crystal is used in hs-pll mode, then the effective frequency is f osc = 40 mhz and t osc =25ns. figure 27-4: bit time partitioning t bit = 1/nominal bit rate nominal bit time = t q * (sync_seg + prop_seg + phase_seg1 + phase_seg2) t q ( ? s) = (2 * (brp + 1))/f osc (mhz) or t q ( ? s) = (2 * (brp + 1)) * t osc ( ? s) input sync propagation segment phase segment 1 phase segment 2 sample point t q nominal bit time bit time intervals signal segment sync
? 2011 microchip technology inc. ds39977d-page 449 pic18f66k80 family 27.9.1 external clock, internal clock and measurable jitter in hs-pll based oscillators the microcontroller clock frequency generated from a pll circuit is subject to a jitter, also defined as phase jitter or phase skew. for its pic18 enhanced micro- controllers, microchip specifies phase jitter ( p jitter ) as being 2% (gaussian distribution, within 3 standard deviations, see parameter f13 in table 31-7 ) and total jitter ( t jitter ) as being 2 * p jitter . the can protocol uses a bit-stuffing technique that inserts a bit of a given polarity following five bits with the opposite polarity. this gives a total of 10 bits transmit- ted without resynchronization (compensation for jitter or phase error). given the random nature of the added jitter error, it can be shown that the total error caused by the jitter tends to cancel itself over time. for a period of 10 bits, it is necessary to add only two jitter intervals to correct for jitter induced error: one interval in the beginning of the 10-bit period and another at the end. the overall effect is shown in figure 27-5 . figure 27-5: effects of phase jitt er on the microcontroller clock and can bit time once these considerations are taken into account, it is possible to show that the relation between the jitter and the total frequency error can be defined as: where jitter is expressed in terms of time and nbt is the nominal bit time. for example, assume a can bit rate of 125 kb/s, which gives an nbt of 8 s. for a 16 mhz clock generated from a 4x pll, the jitter at this clock frequency is: and resultant frequency error is: nominal clock clock with jitter can bit time phase skew (jitter) can bit jitter with jitter ? f t jitter 10 nbt ? ----------------------- - 2 p jitter ? 10 nbt ? ----------------------- - = = 2% 1 16 mhz ------------------- ? 0.02 16 6 ? 10 ----------------- 1.25ns == 21.25 9 ? ? 10 ?? ? 10 8 6 ? ? 10 ?? ? -------------------------------------- -3.125 5 ? ? 10 0.0031% = =
pic18f66k80 family ds39977d-page 450 ? 2011 microchip technology inc. table 27-2 shows the relation between the clock generated by the pll and the frequency error from jitter (measured jitter-induced error of 2%, gaussian distribution, within 3 standard deviations), as a percentage of the nominal clock frequency. this is clearly smaller than the expected drift of a crystal oscillator, typically specified at 100 ppm or 0.01%. if we add jitter to oscillator drift, we have a total frequency drift of 0.0132%. the total oscillator frequency errors for common clock frequencies and bit rates, including both drift and jitter, are shown in table 27-3 . table 27-2: frequency error from jitter at various pll generated clock speeds table 27-3: total frequency error at various pll generated clock speeds (100 ppm oscillator drift, including error from jitter) pll output p jitter t jitter frequency error at various nominal bit times (bit rates) 8 ? s (125 kb/s) 4 ? s (250 kb/s) 2 ? s (500 kb/s) 1 ? s (1 mb/s) 40 mhz 0.5 ns 1 ns 0.00125% 0.00250% 0.005% 0.01% 24 mhz 0.83 ns 1.67 ns 0.00209% 0.00418% 0.008% 0.017% 16 mhz 1.25 ns 2.5 ns 0.00313% 0.00625% 0.013% 0.025% nominal pll output frequency error at various nominal bit times (bit rates) 8 ? s (125 kb/s) 4 ? s (250 kb/s) 2 ? s (500 kb/s) 1 ? s (1 mb/s) 40 mhz 0.01125% 0.01250% 0.015% 0.02% 24 mhz 0.01209% 0.01418% 0.018% 0.027% 16 mhz 0.01313% 0.01625% 0.023% 0.035%
? 2011 microchip technology inc. ds39977d-page 451 pic18f66k80 family 27.9.2 time quanta as already mentioned, the time quanta is a fixed unit derived from the oscillator period and baud rate prescaler. its relationship to t bit and the nominal bit rate is shown in example 27-6 . example 27-6: calculating t q , nominal bit rate and nominal bit time the frequencies of the oscillators in the different nodes must be coordinated in order to provide a system wide specified nominal bit time. this means that all oscilla- tors must have a t osc that is an integral divisor of t q . it should also be noted that although the number of t q is programmable from 4 to 25, the usable minimum is 8t q . there is no assurance that a bit time of less than 8 t q in length will operate correctly. 27.9.3 synchronization segment this part of the bit time is used to synchronize the various can nodes on the bus. the edge of the input signal is expected to occur during the sync segment. the duration is 1 t q . 27.9.4 propagation segment this part of the bit time is used to compensate for phys- ical delay times within the network. these delay times consist of the signal propagation time on the bus line and the internal delay time of the nodes. the length of the propagation segment can be programmed from 1t q to 8 t q by setting the prseg<2:0> bits. 27.9.5 phase buffer segments the phase buffer segments are used to optimally locate the sampling point of the received bit within the nominal bit time. the sampling point occurs between phase segment 1 and phase segment 2. these segments can be lengthened or shortened by the resynchronization process. the end of phase segment 1 determines the sampling point within a bit time. phase segment 1 is programmable from 1 t q to 8 t q in duration. phase segment 2 provides a delay before the next transmitted data transition and is also programmable from 1 t q to 8 t q in duration. however, due to ipt requirements, the actual minimum length of phase segment 2 is 2 t q , or it may be defined to be equal to the greater of phase segment 1 or the information processing time (ipt). the sampling point should be as late as possible or approximately 80% of the bit time. 27.9.6 sample point the sample point is the point of time at which the bus level is read and the value of the received bit is deter- mined. the sampling point occurs at the end of phase segment 1. if the bit timing is slow and contains many t q , it is possible to specify multiple sampling of the bus line at the sample point. the value of the received bit is determined to be the value of the majority decision of three values. the three samples are taken at the sample point and twice before, with a time of t q /2 between each sample. 27.9.7 information processing time the information processing time (ipt) is the time segment starting at the sample point that is reserved for calculation of the subsequent bit level. the can specification defines this time to be less than or equal to 2 t q . the pic18f66k80 family devices define this time to be 2 t q . thus, phase segment 2 must be at least 2 t q long. t q ( ? s) = (2 * (brp + 1))/f osc (mhz) t bit ( ? s) = t q ( ? s) * number of t q per bit interval nominal bit rate (bits/s) = 1/t bit this frequency (f osc ) refers to the effective frequency used. if, for example, a 10 mhz external signal is used along with a pll, then the effective frequency will be 4 x 10 mhz which equals 40 mhz. case 1: for f osc = 16 mhz, brp<5:0> = 00h and nominal bit time = 8 t q : t q = (2 * 1)/16 = 0.125 ? s (125 ns) t bit = 8 * 0.125 = 1 ? s (10 -6 s) nominal bit rate = 1/10 -6 = 10 6 bits/s (1 mb/s) case 2: for f osc = 20 mhz, brp<5:0> = 01h and nominal bit time = 8 t q : t q = (2 * 2)/20 = 0.2 ? s (200 ns) t bit = 8 * 0.2 = 1.6 ? s (1.6 * 10 -6 s) nominal bit rate = 1/1.6 * 10 -6 s = 625,000 bits/s (625 kb/s) case 3: for f osc = 25 mhz, brp<5:0> = 3fh and nominal bit time = 25 t q : t q = (2 * 64)/25 = 5.12 ? s t bit = 25 * 5.12 = 128 ? s (1.28 * 10 -4 s) nominal bit rate = 1/1.28 * 10 -4 = 7813 bits/s (7.8 kb/s)
pic18f66k80 family ds39977d-page 452 ? 2011 microchip technology inc. 27.10 synchronization to compensate for phase shifts between the oscillator frequencies of each of the nodes on the bus, each can controller must be able to synchronize to the relevant signal edge of the incoming signal. when an edge in the transmitted data is detected, the logic will compare the location of the edge to the expected time (sync_seg). the circuit will then adjust the values of phase segment 1 and phase segment 2 as necessary. there are two mechanisms used for synchronization. 27.10.1 hard synchronization hard synchronization is only done when there is a recessive to dominant edge during a bus idle condition, indicating the start of a message. after hard synchroni- zation, the bit time counters are restarted with sync_seg. hard synchronization forces the edge, which has occurred to lie within the synchronization segment of the restarted bit time. due to the rules of synchronization, if a hard synchronization occurs, there will not be a resynchronization within that bit time. 27.10.2 resynchronization as a result of resynchronization, phase segment 1 may be lengthened or phase segment 2 may be short- ened. the amount of lengthening or shortening of the phase buffer segments has an upper bound given by the synchronization jump width (sjw). the value of the sjw will be added to phase segment 1 (see figure 27-6 ) or subtracted from phase segment 2 (see figure 27-7 ). the sjw is programmable between 1 t q and 4 t q . clocking information will only be derived from reces- sive to dominant transitions. the property, that only a fixed maximum number of successive bits have the same value, ensures resynchronization to the bit stream during a frame. the phase error of an edge is given by the position of the edge relative to sync_seg, measured in t q . the phase error is defined in magnitude of t q as follows: ? e = 0 if the edge lies within sync_seg. ? e > 0 if the edge lies before the sample point. ? e < 0 if the edge lies after the sample point of the previous bit. if the magnitude of the phase error is less than, or equal to, the programmed value of the synchronization jump width, the effect of a resynchronization is the same as that of a hard synchronization. if the magnitude of the phase error is larger than the synchronization jump width and if the phase error is positive, then phase segment 1 is lengthened by an amount equal to the synchronization jump width. if the magnitude of the phase error is larger than the resynchronization jump width and if the phase error is negative, then phase segment 2 is shortened by an amount equal to the synchronization jump width. 27.10.3 synchronization rules ? only one synchronization within one bit time is allowed. ? an edge will be used for synchronization only if the value detected at the previous sample point (previously read bus value) differs from the bus value immediately after the edge. ? all other recessive to dominant edges fulfilling rules 1 and 2 will be used for resynchronization, with the exception that a node transmitting a dominant bit will not perform a resynchronization as a result of a recessive to dominant edge with a positive phase error. figure 27-6: lengthening a bit period (adding sjw to phase segment 1) input sync prop segment phase segment 1 phase segment 2 ? sjw sample point t q signal nominal bit length actual bit length bit time segments
? 2011 microchip technology inc. ds39977d-page 453 pic18f66k80 family figure 27-7: shortening a bit period (subtracting sjw from phase segment 2) 27.11 programming time segments some requirements for programming of the time segments: ? prop_seg + phase_seg 1 ? phase_seg 2 ? phase_seg 2 ? sync jump width. for example, assume that a 125 khz can baud rate is desired, using 20 mhz for f osc . with a t osc of 50 ns, a baud rate prescaler value of 04h gives a t q of 500 ns. to obtain a nominal bit rate of 125 khz, the nominal bit time must be 8 ? s or 16 t q . using 1 t q for the sync_seg, 2 t q for the prop_seg and 7 t q for phase segment 1 would place the sample point at 10 t q after the transition. this leaves 6 t q for phase segment 2. by the rules above, the sync jump width could be the maximum of 4 t q . however, normally a large sjw is only necessary when the clock generation of the different nodes is inaccurate or unstable, such as using ceramic resonators. typically, an sjw of 1 is enough. 27.12 oscillator tolerance as a rule of thumb, the bit timing requirements allow ceramic resonators to be used in applications with transmission rates of up to 125 kbit/sec. for the full bus speed range of the can protocol, a quartz oscillator is required. refer to iso11898-1 for oscillator tolerance requirements. sync prop segment phase segment 1 phase segment 2 ? sjw t q sample point nominal bit length actual bit length
pic18f66k80 family ds39977d-page 454 ? 2011 microchip technology inc. 27.13 bit timing configuration registers the baud rate control registers (brgcon1, brgcon2, brgcon3) control the bit timing for the can bus interface. these registers can only be modi- fied when the pic18f66k80 family devices are in configuration mode. 27.13.1 brgcon1 the brp bits control the baud rate prescaler. the sjw<1:0> bits select the synchronization jump width in terms of multiples of t q . 27.13.2 brgcon2 the prseg bits set the length of the propagation seg- ment in terms of t q . the seg1ph bits set the length of phase segment 1 in t q . the sam bit controls how many times the rxcan pin is sampled. setting this bit to a ? 1 ? causes the bus to be sampled three times: twice at t q /2 before the sample point and once at the normal sample point (which is at the end of phase segment 1). the value of the bus is determined to be the value read during at least two of the samples. if the sam bit is set to a ? 0 ?, then the rxcan pin is sampled only once at the sample point. the seg2phts bit controls how the length of phase segment 2 is determined. if this bit is set to a ? 1 ? , then the length of phase segment 2 is determined by the seg2ph bits of brgcon3. if the seg2phts bit is set to a ? 0 ?, then the length of phase segment 2 is the greater of phase segment 1 and the information processing time (which is fixed at 2 t q for the pic18f66k80 family). 27.13.3 brgcon3 the phseg2<2:0> bits set the length (in t q ) of phase segment 2 if the seg2phts bit is set to a ? 1 ?. if the seg2phts bit is set to a ? 0 ?, then the phseg2<2:0> bits have no effect. 27.14 error detection the can protocol provides sophisticated error detection mechanisms. the following errors can be detected. 27.14.1 crc error with the cyclic redundancy check (crc), the trans- mitter calculates special check bits for the bit sequence, from the start of a frame until the end of the data field. this crc sequence is transmitted in the crc field. the receiving node also calculates the crc sequence using the same formula and performs a comparison to the received sequence. if a mismatch is detected, a crc error has occurred and an error frame is generated. the message is repeated. 27.14.2 acknowledge error in the acknowledge field of a message, the transmitter checks if the acknowledge slot (which was sent out as a recessive bit) contains a dominant bit. if not, no other node has received the frame correctly. an acknowl- edge error has occurred, an error frame is generated and the message will have to be repeated. 27.14.3 form error if a node detects a dominant bit in one of the four seg- ments, including end-of-frame (eof), interframe space, acknowledge delimiter or crc delimiter, then a form error has occurred and an error frame is generated. the message is repeated. 27.14.4 bit error a bit error occurs if a transmitter sends a dominant bit and detects a recessive bit, or if it sends a recessive bit and detects a dominant bit, when monitoring the actual bus level and comparing it to the just transmitted bit. in the case where the transmitter sends a recessive bit and a dominant bit is detected during the arbitration field and the acknowledge slot, no bit error is generated because normal arbitration is occurring. 27.14.5 stuff bit error lf, between the start-of-frame (sof) and the crc delimiter, six consecutive bits with the same polarity are detected, the bit stuffing rule has been violated. a stuff bit error occurs and an error frame is generated. the message is repeated. 27.14.6 error states detected errors are made public to all other nodes via error frames. the transmission of the erroneous mes- sage is aborted and the frame is repeated as soon as possible. furthermore, each can node is in one of the three error states; ?error-active?, ?error-passive? or ?bus-off?, according to the value of the internal error counters. the error-active state is the usual state where the bus node can transmit messages and acti- vate error frames (made of dominant bits) without any restrictions. in the error-passive state, messages and passive error frames (made of recessive bits) may be transmitted. the bus-off state makes it temporarily impossible for the node to participate in the bus communication. during this state, messages can neither be received nor transmitted. 27.14.7 error modes and error counters the pic18f66k80 family devices contain two error counters: the receive error counter (rxerrcnt) and the transmit error counter (txerrcnt). the values of both counters can be read by the mcu. these counters are incremented or decremented in accordance with the can bus specification.
? 2011 microchip technology inc. ds39977d-page 455 pic18f66k80 family the pic18f66k80 family devices are error-active if both error counters are below the error-passive limit of 128. they are error-passive if at least one of the error counters equals or exceeds 128. they go to bus-off if the transmit error counter equals or exceeds the bus- off limit of 256. the devices remain in this state until the bus-off recovery sequence is finished. the bus-off recovery sequence consists of 128 occurrences of 11 consecutive recessive bits (see figure 27-8 ). note that the can module, after going bus-off, will recover back to error-active without any intervention by the mcu if the bus remains idle for 128 x 11 bit times. if this is not desired, the error interrupt service routine should address this. the current error mode of the can module can be read by the mcu via the comstat register. additionally, there is an error state warning flag bit, ewarn, which is set if at least one of the error coun- ters equals or exceeds the error warning limit of 96. ewarn is reset if both error counters are less than the error warning limit. figure 27-8: error mo des state diagram 27.15 can interrupts the module has several sources of interrupts. each of these interrupts can be individually enabled or dis- abled. the pir5 register contains interrupt flags. the pie5 register contains the enables for the 8 main inter- rupts. a special set of read-only bits in the canstat register, the icode bits, can be used in combination with a jump table for efficient handling of interrupts. all interrupts have one source, with the exception of the error interrupt and buffer interrupts in mode 1 and 2. any of the error interrupt sources can set the error interrupt flag. the source of the error interrupt can be determined by reading the communication status register, comstat. in mode 1 and 2, there are two interrupt enable/disable and flag bits ? one for all transmit buffers and the other for all receive buffers. the interrupts can be broken up into two categories: receive and transmit interrupts. the receive related interrupts are: ? receive interrupts ? wake-up interrupt ? receiver overrun interrupt ? receiver warning interrupt ? receiver error-passive interrupt the transmit related interrupts are: ? transmit interrupts ? transmitter warning interrupt ? transmitter error-passive interrupt ? bus-off interrupt bus- off error - active error - passive rxerrcnt < 128 or txerrcnt < 128 rxerrcnt ? 128 or txerrcnt ? 128 txerrcnt > 255 128 occurrences of 11 consecutive ?recessive? bits reset
pic18f66k80 family ds39977d-page 456 ? 2011 microchip technology inc. 27.15.1 interrupt code bits to simplify the interrupt handling process in user firm- ware, the ecan module encodes a special set of bits. in mode 0, these bits are icode<3:1> in the canstat register. in mode 1 and 2, these bits are eicode<4:0> in the canstat register. interrupts are internally prioritized such that the higher priority interrupts are assigned lower values. once the highest priority interrupt condition has been cleared, the code for the next highest priority inter- rupt that is pending (if any) will be reflected by the icode bits (see table 27-4 ). note that only those interrupt sources that have their associated interrupt enable bit set will be reflected in the icode bits. in mode 2, when a receive message interrupt occurs, the eicode bits will always consist of ? 10000 ?. user firmware may use fifo pointer bits to actually access the next available buffer. 27.15.2 transmit interrupt when the transmit interrupt is enabled, an interrupt will be generated when the associated transmit buffer becomes empty and is ready to be loaded with a new message. in mode 0, there are separate interrupt enable/ disable and flag bits for each of the three dedicated trans- mit buffers. the txbnif bit will be set to indicate the source of the interrupt. the interrupt is cleared by the mcu, resetting the txbnif bit to a ? 0 ?. in mode 1 and 2, all transmit buffers share one interrupt enable/disable bit and one flag bit. in mode 1 and 2, txbnie in pie5 and txbnif in pir5 indicate when a transmit buffer has com- pleted transmission of its message. txbnif, txbnie and txbnip in pir5, pie5 and ipr5, respectively, are not used in mode 1 and 2. individual transmit buffer interrupts can be enabled or disabled by setting or clearing txbnie and b0ie register bits. when a shared interrupt occurs, user firmware must poll the txreq bit of all transmit buffers to detect the source of interrupt. 27.15.3 receive interrupt when the receive interrupt is enabled, an interrupt will be generated when a message has been successfully received and loaded into the associated receive buffer. this interrupt is activated immediately after receiving the end-of-frame (eof) field. in mode 0, the rxbnif bit is set to indicate the source of the interrupt. the interrupt is cleared by the mcu, resetting the rxbnif bit to a ? 0 ?. in mode 1 and 2, all receive buffers share rxbnie, rxbnif and rxbnip in pie5, pir5 and ipr5, respec- tively. bits, rxbnie, rxbnif and rxbnip, are not used. individual receive buffer interrupts can be con- trolled by the txbnie and bie0 registers. in mode 1, when a shared receive interrupt occurs, user firmware must poll the rxful bit of each receive buffer to detect the source of interrupt. in mode 2, a receive interrupt indicates that the new message is loaded into fifo. fifo can be read by using fifo pointer bits, fp. table 27-4: values for icode<2:0> 27.15.4 message error interrupt when an error occurs during transmission or reception of a message, the message error flag, irxif, will be set and if the irxie bit is set, an interrupt will be generated. this is intended to be used to facilitate baud rate determination when used in conjunction with listen only mode. 27.15.5 bus activity wake-up interrupt when the pic18f66k80 family devices are in sleep mode and the bus activity wake-up interrupt is enabled, an interrupt will be generated and the wakif bit will be set when activity is detected on the can bus. this interrupt causes the pic18f66k80 family devices to exit sleep mode. the interrupt is reset by the mcu, clearing the wakif bit. 27.15.6 error interrupt when the can module error interrupt (errie in pie5) is enabled, an interrupt is generated if an overflow con- dition occurs, or if the error state of the transmitter or receiver has changed. the error flags in comstat will indicate one of the following conditions. icode <2:0> interrupt boolean expression 000 none err ?wak ?tx0 ?tx1 ?tx2 ?rx0 ?rx1 001 error err 010 txb2 err ?tx0 ?tx1 ?tx2 011 txb1 err ?tx0 ?tx1 100 txb0 err ?tx0 101 rxb1 err ?tx0 ?tx1 ?tx2 ?rx0 ?rx1 110 rxb0 err ?tx0 ?tx1 ?tx2 ?rx0 111 wake on interrupt err ?tx0 ?tx1 ?tx2 ?rx0 ?rx1 ?wak legend: err = errif * errie rx0 = rxb0if * rxb0ie tx0 = txb0if * txb0ie rx1 = rxb1if * rxb1ie tx1 = txb1if * txb1ie wak = wakif * wakie tx2 = txb2if * txb2ie
? 2011 microchip technology inc. ds39977d-page 457 pic18f66k80 family 27.15.6.1 receiver overflow an overflow condition occurs when the mab has assembled a valid received message (the message meets the criteria of the acceptance filters) and the receive buffer associated with the filter is not available for loading of a new message. the associated rxbnovfl bit in the comstat register will be set to indicate the overflow condition. this bit must be cleared by the mcu. 27.15.6.2 receiver warning the receive error counter has reached the mcu warning limit of 96. 27.15.6.3 transmitter warning the transmit error counter has reached the mcu warning limit of 96. 27.15.6.4 receiver bus passive this will occur when the device has gone to the error- passive state because the receive error counter is greater or equal to 128. 27.15.6.5 transmitter bus passive this will occur when the device has gone to the error- passive state because the transmit error counter is greater or equal to 128. 27.15.6.6 bus-off the transmit error counter has exceeded 255 and the device has gone to bus-off state.
pic18f66k80 family ds39977d-page 458 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds39977d-page 459 pic18f66k80 family 28.0 special features of the cpu the pic18f66k80 family of devices includes several features intended to maximize reliability and minimize cost through elimination of external components. these include: ? oscillator selection ? resets: - power-on reset (por) - power-up timer (pwrt) - oscillator start-up timer (ost) - brown-out reset (bor) ? interrupts ? watchdog timer (wdt) and on-chip regulator ? fail-safe clock monitor ? two-speed start-up ? code protection ? id locations ? in-circuit serial programming? the oscillator can be configured for the application depending on frequency, power, accuracy and cost. all of the options are discussed in detail in section 3.0 ?oscillator configurations? . a complete discussion of device resets and interrupts is available in previous sections of this data sheet. in addition to their power-up and oscillator start-up timers provided for resets, the pic18f66k80 family of devices has a watchdog timer, which is either perma- nently enabled via the configuration bits or software controlled (if configured as disabled). the inclusion of an internal rc oscillator (lf-intosc) also provides the additional benefits of a fail-safe clock monitor (fscm) and two-speed start-up. fscm provides for background monitoring of the peripheral clock and automatic switchover in the event of its fail- ure. two-speed start-up enables code to be executed almost immediately on start-up, while the primary clock source completes its start-up delays. all of these features are enabled and configured by setting the appropriate configuration register bits. 28.1 configuration bits the configuration bits can be programmed (read as ? 0 ?) or left unprogrammed (read as ? 1 ?) to select various device configurations. these bits are mapped starting at program memory location, 300000h. the user will note that address, 300000h, is beyond the user program memory space. in fact, it belongs to the configuration memory space (300000h-3fffffh), which can only be accessed using table reads and table writes. software programming the configuration registers is done in a manner similar to programming the flash memory. the wr bit in the eecon1 register starts a self-timed write to the configuration register. in normal operation mode, a tblwt instruction with the tblptr pointing to the configuration register sets up the address and the data for the configuration register write. setting the wr bit starts a long write to the configuration register. the configuration registers are written a byte at a time. to write or erase a configuration cell, a tblwt instruction can write a ? 1 ? or a ? 0 ? into the cell. for additional details on flash programming, refer to section 7.5 ?writing to flash program memory? .
pic18f66k80 family ds39977d-page 460 ? 2011 microchip technology inc. table 28-1: configuration bits and device ids file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 default/ unprogrammed value 300000h config1l ?xinst ? soscsel1 soscsel0 intoscsel ?reten -1-1 11-1 300001h config1h ieso fcmen ? pllcfg fosc3 fosc2 fosc1 fosc0 00-0 1000 300002h config2l ? borpwr1 borwpr0 borv1 borv0 boren1 boren0 pwrten -111 1111 300003h config2h ? wdtps4 wdtps3 wdtps2 wdtps1 wdtps0 wdten1 wdten0 -111 1111 300005h config3h mclre ? ? ? msspmsk t3ckmx (1,3) t0ckmx (1) canmx 1--- 1qq1 300006h config4l debug ? ?bbsiz0 ? ? ?stvren 1--1 ---1 300008h config5l ? ? ? ? cp3 cp2 cp1 cp0 ---- 1111 300009h config5h cpd cpb ? ? ? ? ? ? 11-- ---- 30000ah config6l ? ? ? ? wrt3 wrt2 wrt1 wrt0 ---- 1111 30000bh config6h wrtd wrtb wrtc ? ? ? ? ? 111- ---- 30000ch config7l ? ? ? ? ebtr3 ebtr2 ebtr1 ebtr0 ---- 1111 30000dh config7h ?ebtrb ? ? ? ? ? ? -1-- ---- 3ffffeh devid1 (2) dev2 dev1 dev0 rev4 rev3 rev2 rev1 rev0 xxxx xxxx 3fffffh devid2 (2) dev10 dev9 dev8 dev7 dev6 dev5 dev4 dev3 xxxx xxxx legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition. shaded cells are unimplemented, read as ? 0 ?. note 1: implemented only on the 64-pin devices (pic18f6xk80). 2: see register 28-13 for devid1 values. devid registers are read-only and cannot be programmed by the user. 3: maintain as ? 0 ? on 28-pin, 40-pin and 44-pin devices.
? 2011 microchip technology inc. ds39977d-page 461 pic18f66k80 family register 28-1: config1l: configuration register 1 low (byte address 300000h) u-0 r/p-1 u-0 r/p-1 r/p-1 r/p-1 u-0 r/p-1 ?xinst ? soscsel1 soscsel0 intoscsel ? reten bit 7 bit 0 legend: p = programmable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 xinst: extended instruction set enable bit 1 = instruction set extension and indexed addressing mode are enabled 0 = instruction set extension and indexed addressing mode are disabled (legacy mode) bit 5 unimplemented: read as ? 0 ? bit 4-3 soscsel<1:0>: sosc power selection and mode configuration bits 11 = high-power sosc circuit is selected 10 = digital (sclki) mode; i/o port functionality of rc0 and rc1 is enabled 01 = low-power sosc circuit is selected 00 = reserved bit 2 intoscsel: lf-intosc low-power enable bit 1 = lf-intosc in high-power mode during sleep 0 = lf-intosc in low-power mode during sleep bit 1 unimplemented: read as ? 0 ? bit 0 reten : v reg sleep enable bit 1 = ultra low-power regulator is disabled. regulator power in sleep mode is controlled by regslp (wdtcon<7>). 0 = ultra low-power regulator is enabled. regulator power in sleep mode is controlled by sreten (wdtcon<4>).
pic18f66k80 family ds39977d-page 462 ? 2011 microchip technology inc. register 28-2: config1h: configuration register 1 high (byte address 300001h) r/p-0 r/p-0 u-0 u-0 r/p-1 r/p-0 r/p-0 r/p-0 ieso fcmen ?pllcfg (1) fosc3 (2) fosc2 (2) fosc1 (2) fosc0 (2) bit 7 bit 0 legend: p = programmable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ieso: internal/external oscillator switchover bit 1 = two-speed start-up is enabled 0 = two-speed start-up is disabled bit 6 fcmen: fail-safe clock monitor enable bit 1 = fail-safe clock monitor is enabled 0 = fail-safe clock monitor is disabled bit 5 unimplemented: read as ? 0 ? bit 4 pllcfg: 4x pll enable bit (1) 1 = oscillator is multiplied by 4 0 = oscillator is used directly bit 3-0 fosc<3:0>: oscillator selection bits (2) 1101 = ec1, ec oscillator (low power, dc-160 khz) 1100 = ec1io, ec oscillator with clkout function on ra6 (low power, dc-160 khz) 1011 = ec2, ec oscillator (medium power, 160 khz-16 mhz) 1010 = ec2io, ec oscillator with clkout function on ra6 (medium power, 160 khz-16 mhz) 0101 = ec3, ec oscillator (high power, 16 mhz-64 mhz) 0100 = ec3io, ec oscillator with clkout function on ra6 (high power, 16 mhz-64 mhz) 0011 = hs1, hs oscillator (medium power, 4 mhz-16 mhz) 0010 = hs2, hs oscillator (high power, 16 mhz-25 mhz) 0001 = xt oscillator 0000 = lp oscillator 0111 = rc, external rc oscillator 0110 = rcio, external rc oscillator with cklout function on ra6 1000 = intio2, internal rc oscillator 1001 = intio1, internal rc oscillator with clkout function on ra6 note 1: not valid for the intiox pll mode. 2: intio + pll can be enabled only by the pllen bit (osctune<6>). other pll modes can be enabled by either the pllen bit or the pllcfg (config1h<4>) bit.
? 2011 microchip technology inc. ds39977d-page 463 pic18f66k80 family register 28-3: config2l: configuration register 2 low (byte address 300002h) u-0 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 ?borpwr1 (1) borpwr0 (1) borv1 (1) borv0 (1) boren1 (2) boren0 (2) pwrten (2) bit 7 bit 0 legend: p = programmable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-5 borpwr<1:0>: bormv power-level bits (1) 11 = zpborvmv instead of bormv is selected 10 = bormv is set to a high-power level 01 = bormv is set to a medium power level 00 = bormv is set to a low-power level bit 4-3 borv<1:0>: brown-out reset voltage bits (1) 11 =b vdd is set to 1.8v 10 =b vdd is set to 2.0v 01 =b vdd is set to 2.7v 00 =b vdd is set to 3.0v bit 2-1 boren<1:0>: brown-out reset enable bits (2) 11 = brown-out reset is enabled in hardware only (sboren is disabled) 10 = brown-out reset is enabled in hardware only and disabled in sleep mode (sboren is disabled) 01 = brown-out reset is enabled and controlled by software (sboren is enabled) 00 = brown-out reset is disabled in hardware and software bit 0 pwrten : power-up timer enable bit (2) 1 = pwrt disabled 0 = pwrt enabled note 1: for the specifications, see section 31.1 ?dc characteristics: supply voltage pic18f66k80 family (industrial/extended)? . 2: the power-up timer is decoupled from brown-out reset, allowing these features to be independently controlled.
pic18f66k80 family ds39977d-page 464 ? 2011 microchip technology inc. register 28-4: config2h: configuration register 2 high (byte address 300003h) u-0 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 ? wdtps4 wdtps3 wdtps2 wdtps1 wdtps0 wdten1 wdten0 bit 7 bit 0 legend: p = programmable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-2 wdtps<4:0>: watchdog timer postscale select bits 11111 = reserved 10100 = 1:1,048,576 (4,194.304s) 10011 = 1:524,288 (2,097.152s) 10010 = 1:262,144 (1,048.576s) 10001 = 1:131,072 (524.288s) 10000 = 1:65,536 (262.144s) 01111 = 1:32,768 (131.072s) 01110 = 1:16,384 (65.536s) 01101 = 1:8,192 (32.768s) 01100 = 1:4,096 (16.384s) 01011 = 1:2,048 (8.192s) 01010 = 1:1,024 (4.096s) 01001 = 1:512 (2.048s) 01000 = 1:256 (1.024s) 00111 = 1:128 (512 ms) 00110 = 1:64 (256 ms) 00101 = 1:32 (128 ms) 00100 = 1:16 (64 ms) 00011 = 1:8 (32 ms) 00010 = 1:4 (16 ms) 00001 = 1:2 (8 ms) 00000 = 1:1 (4 ms) bit 1-0 wdten<1:0>: watchdog timer enable bits 11 = wdt is enabled in hardware; swdten bit is disabled 10 = wdt is controlled by the swdten bit setting 01 = wdt is enabled only while the device is active and is disabled in sleep mode; swdten bit is disabled 00 = wdt is disabled in hardware; swdten bit is disabled
? 2011 microchip technology inc. ds39977d-page 465 pic18f66k80 family register 28-5: config3h: configuration register 3 high (byte address 300005h) r/p-1 u-0 u-0 u-0 r/p-1 r/p-1 r/p-1 r/p-1 mclre ? ? ? msspmsk t3ckmx (1) t0ckmx (1) canmx bit 7 bit 0 legend: p = programmable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 mclre: mclr pin enable bit 1 = mclr pin is enabled; re3 input pin is disabled 0 = re3 input pin is enabled; mclr is disabled bit 6-4 unimplemented: read as ? 0 ? bit 3 msspmsk: mssp v3 7-bit address masking mode enable bit 1 = 7-bit address masking mode is enabled 0 = 5-bit address masking mode is enabled bit 2 t3ckmx: timer3 clock input mux bit (1) 1 = timer3 gets its clock input from the rg2/t3cki pin on 64-pin packages 0 = timer3 gets its clock input from the rb5/t3cki pin on 64-pin packages bit 1 t0ckmx: timer0 clock input mux bit (1) 1 = timer0 gets its clock input from the rb5/t0cki pin on 64-pin packages 0 = timer0 gets its clock input from the rg4/t0cki pin on 64-pin packages bit 0 canmx: ecan mux bit 1 = cantx and canrx pins are located on rb2 and rb3, respectively 0 = cantx and canrx pins are located on rc6 and rc7, respectively (28-pin and 40/44-pin packages) or on re4 and re5, respectively (64-pin package) note 1: implemented only on the 64-pin devices (pic18f6xk80). maintain as ? 0 ? on 28-pin, 40-pin and 44-pin devices.
pic18f66k80 family ds39977d-page 466 ? 2011 microchip technology inc. register 28-6: config4l: configuration register 4 low (byte address 300006h) r/p-1 u-0 u-0 r/p-0 u-0 u-0 u-0 r/p-1 debug ? ? bbsiz0 ? ? ?stvren bit 7 bit 0 legend: p = programmable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 debug : background debugger enable bit 1 = background debugger is disabled, rb6 and rb7 are configured as general purpose i/o pins 0 = background debugger is enabled, rb6 and rb7 are dedicated to in-circuit debug bit 6-5 unimplemented: read as ? 0 ? bit 4 bbsiz0: boot block size select bit 1 = 2 kw boot block size 0 = 1 kw boot block size bit 3-1 unimplemented: read as ? 0 ? bit 0 stvren: stack full/underflow reset enable bit 1 = stack full/underflow will cause a reset 0 = stack full/underflow will not cause a reset
? 2011 microchip technology inc. ds39977d-page 467 pic18f66k80 family register 28-7: config5l: configuration register 5 low (byte address 300008h) u-0 u-0 u-0 u-0 r/c-1 r/c-1 r/c-1 r/c-1 ? ? ? ? cp3 cp2 cp1 cp0 bit 7 bit 0 legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 unimplemented: read as ? 0 ? bit 3 cp3: code protection bit 1 = block 3 is not code-protected (1) 0 = block 3 is code-protected (1) bit 2 cp2: code protection bit 1 = block 2 is not code-protected (1) 0 = block 2 is code-protected (1) bit 1 cp1: code protection bit 1 = block 1 is not code-protected (1) 0 = block 1 is code-protected (1) bit 0 cp0: code protection bit 1 = block 0 is not code-protected (1) 0 = block 0, is code-protected (1) note 1: for the memory size of the blocks, see figure 28-6 .
pic18f66k80 family ds39977d-page 468 ? 2011 microchip technology inc. register 28-8: config5h: configuration register 5 high (byte address 300009h) r/c-1 r/c-1 u-0 u-0 u-0 u-0 u-0 u-0 cpd cpb ? ? ? ? ? ? bit 7 bit 0 legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 cpd: data eeprom code protection bit 1 = data eeprom is not code-protected 0 = data eeprom is code-protected bit 6 cpb: boot block code protection bit 1 = boot block is not code-protected (1) 0 = boot block is code-protected (1) bit 5-0 unimplemented: read as ? 0 ? note 1: for the memory size of the blocks, see figure 28-6 . the boot block size changes with bbsiz0.
? 2011 microchip technology inc. ds39977d-page 469 pic18f66k80 family register 28-9: config6l: configuration register 6 low (byte address 30000ah) u-0 u-0 u-0 u-0 r/c-1 r/c-1 r/c-1 r/c-1 ? ? ? ? wrt3 wrt2 wrt1 wrt0 bit 7 bit 0 legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 unimplemented: read as ? 0 ? bit 3 wrt3: write protection bit 1 = block 3 is not write-protected (1) 0 = block 3 is write-protected (1) bit 2 wrt2: write protection bit 1 = block 2 is not write-protected (1) 0 = block 2 is write-protected (1) bit 1 wrt1: write protection bit 1 = block 1 is not write-protected (1) 0 = block 1 is write-protected (1) bit 0 wrt0: write protection bit 1 = block 0 is not write-protected (1) 0 = block 0 is write-protected (1) note 1: for the memory size of the blocks, see figure 28-6 .
pic18f66k80 family ds39977d-page 470 ? 2011 microchip technology inc. register 28-10: config6h: configuration register 6 high (byte address 30000bh) r/c-1 r/c-1 r-1 u-0 u-0 u-0 u-0 u-0 wrtd wrtb wrtc (1) ? ? ? ? ? bit 7 bit 0 legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 wrtd: data eeprom write protection bit 1 = data eeprom is not write-protected 0 = data eeprom is write-protected bit 6 wrtb: boot block write protection bit 1 = boot block is not write-protected (2) 0 = boot block is write-protected (2) bit 5 wrtc: configuration register write protection bit (1) 1 = configuration registers are not write-protected (2) 0 = configuration registers are write-protected (2) bit 4-0 unimplemented: read as ? 0 ? note 1: this bit is read-only in normal execution mode; it can be written only in program mode. 2: for the memory size of the blocks, see figure 28-6 .
? 2011 microchip technology inc. ds39977d-page 471 pic18f66k80 family register 28-11: config7l: configuration register 7 low (byte address 30000ch) u-0 u-0 u-0 u-0 r/c-1 r/c-1 r/c-1 r/c-1 ? ? ? ? ebtr3 ebtr2 ebtr1 ebtr0 bit 7 bit 0 legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 unimplemented: read as ? 0 ? bit 3 ebtr3: table read protection bit 1 = block 3 is not protected from table reads executed in other blocks (1) 0 = block 3 is protected from table reads executed in other blocks (1) bit 2 ebtr2 : table read protection bit 1 = block 2 is not protected from table reads executed in other blocks (1) 0 = block 2 is protected from table reads executed in other blocks (1) bit 1 ebtr1: table read protection bit 1 = block 1 is not protected from table reads executed in other blocks (1) 0 = block 1 is protected from table reads executed in other blocks (1) bit 0 ebtr0: table read protection bit 1 = block 0 is not protected from table reads executed in other blocks (1) 0 = block 0 is protected from table reads executed in other blocks (1) note 1: for the memory size of the blocks, see figure 28-6 .
pic18f66k80 family ds39977d-page 472 ? 2011 microchip technology inc. register 28-12: config7h: configuration register 7 high (byte address 30000dh) u-0 r/c-1 u-0 u-0 u-0 u-0 u-0 u-0 ? ebtrb ? ? ? ? ? ? bit 7 bit 0 legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 ebtrb: boot block table read protection bit 1 = boot block is not protected from table reads executed in other blocks (1) 0 = boot block is protected from table reads executed in other blocks (1) bit 5-0 unimplemented: read as ? 0 ? note 1: for the memory size of the blocks, see figure 28-6 .
? 2011 microchip technology inc. ds39977d-page 473 pic18f66k80 family register 28-13: devid1: device id register 1 for the pic18f66k80 family rrrrrrrr dev2 dev1 dev0 rev4 rev3 rev2 rev1 rev0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 dev<2:0>: device id bits these bits are used with the dev<10:3> bits in the device id register 2 to identify the part number: 000 = pic18f46k80, pic18lf26k80 001 = pic18f26k80, pic18lf65k80 010 = pic18f65k80, pic18lf45k80 011 = pic18f45k80, pic18lf25k80 100 = pic18f25k80 110 = pic18lf66k80 111 = pic18f66k80, pic18lf46k80 bit 4-0 rev<4:0>: revision id bits these bits are used to indicate the device revision. register 28-14: devid2: device id register 2 for the pic18f66k80 family rrrrrrrr dev10 (1) dev9 (1) dev8 (1) dev7 (1) dev6 (1) dev5 (1) dev4 (1) dev3 (1) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 dev<10:3>: device id bits (1) these bits are used with the dev<2:0> bits in the device id register 1 to identify the part number. note 1: these values for dev<10:3> may be shared with other devices. the specific device is always identified by using the entire dev<10:0> bit sequence.
pic18f66k80 family ds39977d-page 474 ? 2011 microchip technology inc. 28.2 watchdog timer (wdt) for the pic18f66k80 family of devices, the wdt is driven by the lf-intosc source. when the wdt is enabled, the clock source is also enabled. the nominal wdt period is 4 ms and has the same stability as the lf-intosc oscillator. the 4 ms period of the wdt is multiplied by a 16-bit postscaler. any output of the wdt postscaler is selected by a multiplexer, controlled by bits in configuration register 2h. available periods range from 4 ms to 4,194 seconds (about one hour). the wdt and postscaler are cleared when any of the following events occur: a sleep or clrwdt instruction is executed, the ircf bits (osccon<6:4>) are changed or a clock failure has occurred. the wdt can be operated in one of four modes as determined by wdten<1:0> (config2h<1:0>. the four modes are: ?wdt enabled ? wdt disabled ? wdt under software control, swdten (wdtcon<0>) ?wdt - enabled during normal operation - disabled during sleep figure 28-1: wdt block diagram note 1: the clrwdt and sleep instructions clear the wdt and postscaler counts when executed. 2: changing the setting of the ircf bits (osccon<6:4>) clears the wdt and postscaler counts. 3: when a clrwdt instruction is executed, the postscaler count will be cleared. intosc source wdt reset wdt counter programmable postscaler 1:1 to 1:1,048,576 enable wdt wdtps<3:0> clrwdt 4 reset all device resets sleep ? 128 change on ircf bits intosc source enable wdt swdten wdten<1:0> wdten1 wdten0 wdt enabled, swdten disabled wdt controlled with swdten bit setting wdt enabled only while device active, disabled wdt disabled in hardware, swdten disabled wake-up from power-manage modes
? 2011 microchip technology inc. ds39977d-page 475 pic18f66k80 family 28.2.1 control register register 28-15 shows the wdtcon register. this is a readable and writable register which contains a control bit that allows software to override the wdt enable configuration bit, but only if the configuration bit has disabled the wdt. table 28-2: summary of watchdog timer registers register 28-15: wdtcon: wat chdog timer control register r/w-0 u-0 r-x r/w-0 u-0 r/w-x r/w-x r/w-0 regslp (3) ?ulplvlsreten (2) ? ulpen ulpsink swdten (1) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 regslp: regulator voltage sleep enable bit (3) 1 = regulator goes into low-power mode when device?s sleep mode is enabled 0 = regulator stays in normal mode when device?s sleep mode is activated bit 6 unimplemented : read as ? 0 ? bit 5 ulplvl: ultra low-power wake-up output bit not valid unless ulpen = 1 . 1 = voltage on ra0 pin > ~ 0.5v 0 = voltage on ra0 pin < ~ 0.5v. bit 4 sreten: regulator voltage sleep disable bit (2) 1 = if r e ten (config1l<0>) = 0 and the regulator is enabled, the device goes into ultra low-power mode in sleep 0 = the regulator is on when device?s sleep mode is enabled and the low-power mode is controlled by regslp bit 3 unimplemented : read as ? 0 ? bit 2 ulpen: ultra low-power wake-up module enable bit 1 = ultra low-power wake-up module is enabled; ulplvl bit indicates comparator output 0 = ultra low-power wake-up module is disabled bit 1 ulpsink: ultra low-power wake-up current sink enable bit not valid unless ulpen = 1 . 1 = ultra low-power wake-up current sink is enabled 0 = ultra low-power wake-up current sink is disabled bit 0 swdten: software controlled watchdog timer enable bit (1) 1 = watchdog timer is on 0 = watchdog timer is off note 1: this bit has no effect if the configuration bits, wdten<1:0>, are enabled. 2: this bit is available only when reten = 0 . 3: this bit is disabled on pic18lf devices. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 rcon ipen sboren cm ri to pd por bor wdtcon regslp ?ulplvlsreten ? ulpen ulpsink swdten legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the watchdog timer.
pic18f66k80 family ds39977d-page 476 ? 2011 microchip technology inc. 28.3 on-chip voltage regulator all of the pic18f66k80 family devices power their core digital logic at a nominal 3.3v. for designs that are required to operate at a higher typical voltage, such as 5v, all family devices incorporate two on-chip regula- tors that allows the device to run its core logic from v dd . those regulators are: ? normal on-chip regulator ? ultra low-power, on-chip regulator the hardware configuration of these regulators are the same and are explained in section 28.3.1 . the regula- tors? only differences relate to when the device enters sleep, as explained in section 28.3.3 . 28.3.1 regulator enable mode (pic18fxxkxx devices) on pic18fxxkxx devices, the regulator is enabled and a low-esr filter capacitor must be connected to the v ddcore /v cap pin (see figure 28-2 ). this helps maintain the regulator?s stability. the recommended value for the filter capacitor is given in section 31.1 dc characteristics . 28.3.2 regulator disable mode (pic18lfxxkxx devices) on pic18 lf xxkxx devices, the regulator is disabled and the power to the core is supplied directly by v dd . the voltage levels for v dd must not exceed the speci- fied v ddcore levels. a 0.1 ? f capacitor should be connected to the v ddcore /v cap pin. on the pic18fxxkxx devices, the overall voltage budget is very tight. the regulator should operate the device down to 1.8v. when v dd drops below 3.3v, the regulator no longer regulates, but the output voltage follows the input until v dd reaches 1.8v. below this voltage, the output of the regulator output may drop to 0v. figure 28-2: connections for the f and lf parts v dd v ddcore /v cap v ss c f 5v (1) v dd v ddcore /v cap (2) v ss 3.3v (1) note 1: these are typical operating voltages. for the full operating ranges of v dd and v ddcore , see section 31.1 dc characteristics . 2: when the regulator is disabled, v ddcore /v cap must be connected to a 0.1 ? f capacitor. pic18f66k80 pic18lf66k80 0.1 ? f capacitor
? 2011 microchip technology inc. ds39977d-page 477 pic18f66k80 family 28.3.3 operation of regulator in sleep the difference in the two regulators? operation arises with sleep mode. the ultra low-power regulator gives the device the lowest current in the regulator enabled mode. the on-chip regulator can go into a lower power mode when the device goes to sleep by setting the regslp bit (wdtcon<7>). this puts the regulator in a standby mode so that the device consumes much less current. the on-chip regulator can also go into the ultra low- power mode, which consumes the lowest current possible with the regulator enabled. this mode is controlled by the reten bit (config1l<0>) and sreten bit (wdtcon<4>). the various modes of regulator operation are shown in table 28-3 . when the ultra low-power regulator is in sleep mode, the internal reference voltages in the chip will be shut off and any interrupts referring to the internal reference will not wake up the device. if the bor or lvd is enabled, the regulator will keep the internal references on and the lowest possible current will not be achieved. when using the ultra low-power regulator in sleep mode, the device will take about 250 ? s to start executing code after it wakes up. table 28-3: sleep mode regulator settings (1) device power mode regslp wdtcon<7> sreten wdtcon<4> r e ten config1l<0> pic18 f xxk80 normal operation (sleep) 0x1 pic18 f xxk80 low-power mode (sleep) 1x1 pic18 f xxk80 normal operation (sleep) 000 pic18 f xxk80 low-power mode (sleep) 100 pic18 f xxk80 ultra low-power mode (sleep) x10 pic18 lf xxk80 reserved (2) x don?t care 0 pic18 lf xxk80 regulator bypass mode (sleep) (2) xx1 note 1: x ? indicates that v it status is invalid. 2: the ultra low-power regulator should be disabled (reten = 1 , ulp disabled) on pic18 lf xxk80 devices to obtain the lowest possible sleep current.
pic18f66k80 family ds39977d-page 478 ? 2011 microchip technology inc. 28.4 two-speed start-up the two-speed start-up feature helps to minimize the latency period from oscillator start-up to code execution by allowing the microcontroller to use the intosc (lf-intosc, mf-intosc, hf-intosc) oscillator as a clock source until the primary clock source is available. it is enabled by setting the ieso configuration bit. two-speed start-up should be enabled only if the primary oscillator mode is lp, xt or hs (crystal-based modes). other sources do not require an ost start-up delay; for these, two-speed start-up should be disabled. when enabled, resets and wake-ups from sleep mode cause the device to configure itself to run from the internal oscillator block as the clock source, following the time-out of the power-up timer after a power-on reset is enabled. this allows almost immediate code execution while the primary oscillator starts and the ost is running. once the ost times out, the device automatically switches to pri_run mode. to use a higher clock speed on wake-up, the intosc or postscaler clock sources can be selected to provide a higher clock speed by setting bits, ircf<2:0>, immediately after reset. for wake-ups from sleep, the intosc or postscaler clock sources can be selected by setting the ircf2:0> bits prior to entering sleep mode. in all other power-managed modes, two-speed start- up is not used. the device will be clocked by the currently selected clock source until the primary clock source becomes available. the setting of the ieso bit is ignored. 28.4.1 special considerations for using two-speed start-up while using the intosc oscillator in two-speed start- up, the device still obeys the normal command sequences for entering power-managed modes, including multiple sleep instructions (refer to section 4.1.4 ?multiple sleep commands? ). in practice, this means that user code can change the scs<1:0> bit settings or issue sleep instructions before the ost times out. this would allow an application to briefly wake-up, perform routine ?housekeeping? tasks and return to sleep before the device starts to operate from the primary oscillator. user code can also check if the primary clock source is currently providing the device clocking by checking the status of the osts bit (osccon<3>). if the bit is set, the primary oscillator is providing the clock. otherwise, the internal oscillator block is providing the clock during wake-up from reset or sleep mode. figure 28-3: timing transition for two-speed start-up (intosc to hspll) q1 q3 q4 osc1 peripheral program pc pc + 2 intosc pll clock q1 pc + 6 q2 output q3 q4 q1 cpu clock pc + 4 clock counter q2 q2 q3 note 1: t ost = 1024 t osc ; t pll = 2 ms (approx). these intervals are not shown to scale. 2: clock transition typically occurs within 2-4 t osc . wake from interrupt event t pll (1) 12 n-1n clock osts bit set transition (2) multiplexer t ost (1)
? 2011 microchip technology inc. ds39977d-page 479 pic18f66k80 family 28.5 fail-safe clock monitor the fail-safe clock monitor (fscm) allows the microcontroller to continue operation in the event of an external oscillator failure by automatically switching the device clock to the internal oscillator block. the fscm function is enabled by setting the fcmen configuration bit. when fscm is enabled, the lf-intosc oscillator runs at all times to monitor clocks to peripherals and provide a backup clock in the event of a clock failure. clock monitoring (shown in figure 28-4 ) is accomplished by creating a sample clock signal, which is the output from the lf-intosc divided by 64. this allows ample time between fscm sample clocks for a peripheral clock edge to occur. the peripheral device clock and the sample clock are presented as inputs to the clock monitor (cm) latch. the cm is set on the falling edge of the device clock source, but cleared on the rising edge of the sample clock. figure 28-4: fscm block diagram clock failure is tested for on the falling edge of the sample clock. if a sample clock falling edge occurs while cm is still set, a clock failure has been detected ( figure 28-5 ). this causes the following: ? the fscm generates an oscillator fail interrupt by setting bit, oscfif (pir2<7>) ? the device clock source switches to the internal oscillator block (osccon is not updated to show the current clock source ? this is the fail-safe condition) ?the wdt is reset during switchover, the postscaler frequency from the internal oscillator block may not be sufficiently stable for timing-sensitive applications. in these cases, it may be desirable to select another clock configuration and enter an alternate power-managed mode. this can be done to attempt a partial recovery or execute a controlled shut- down. see section 4.1.4 ?multiple sleep commands? and section 28.4.1 ?special considerations for using two-speed start-up? for more details. to use a higher clock speed on wake-up, the intosc or postscaler clock sources can be selected to provide a higher clock speed by setting bits, ircf<2:0>, immediately after reset. for wake-ups from sleep, the intosc or postscaler clock sources can be selected by setting the ircf<2:0> bits prior to entering sleep mode. the fscm will detect only failures of the primary or secondary clock sources. if the internal oscillator block fails, no failure would be detected nor would any action be possible. 28.5.1 fscm and the watchdog timer both the fscm and the wdt are clocked by the intosc oscillator. since the wdt operates with a separate divider and counter, disabling the wdt has no effect on the operation of the intosc oscillator when the fscm is enabled. as already noted, the clock source is switched to the intosc clock when a clock failure is detected. depending on the frequency selected by the ircf<2:0> bits, this may mean a substantial change in the speed of code execution. if the wdt is enabled with a small prescale value, a decrease in clock speed allows a wdt time-out to occur and a subsequent device reset. for this reason, fail-safe clock events also reset the wdt and postscaler, allowing it to start timing from when execution speed was changed and decreasing the likelihood of an erroneous time-out. 28.5.2 exiting fail-safe operation the fail-safe condition is terminated by either a device reset or by entering a power-managed mode. on reset, the controller starts the primary clock source specified in configuration register 1h (with any required start-up delays that are required for the oscillator mode, such as the ost or pll timer). the intosc multiplexer provides the device clock until the primary clock source becomes ready (similar to a two- speed start-up). the clock source is then switched to the primary clock (indicated by the osts bit in the osccon register becoming set). the fail-safe clock monitor then resumes monitoring the peripheral clock. the primary clock source may never become ready during start-up. in this case, operation is clocked by the intosc multiplexer. the osccon register will remain in its reset state until a power-managed mode is entered. peripheral intosc 64 s c q (32 ? s) 488 hz (2.048 ms) clock monitor latch (cm) (edge-triggered) clock failure detected source clock q
pic18f66k80 family ds39977d-page 480 ? 2011 microchip technology inc. figure 28-5: fscm timing diagram 28.5.3 fscm interrupts in power-managed modes by entering a power-managed mode, the clock multiplexer selects the clock source selected by the osccon register. fail-safe clock monitoring of the power-managed clock source resumes in the power-managed mode. if an oscillator failure occurs during power-managed operation, the subsequent events depend on whether or not the oscillator failure interrupt is enabled. if enabled (oscfif = 1 ), code execution will be clocked by the intosc multiplexer. an automatic transition back to the failed clock source will not occur. if the interrupt is disabled, subsequent interrupts while in idle mode will cause the cpu to begin executing instructions while being clocked by the intosc source. 28.5.4 por or wake from sleep the fscm is designed to detect oscillator failure at any point after the device has exited power-on reset (por) or low-power sleep mode. when the primary device clock is ec, rc or intosc modes, monitoring can begin immediately following these events. for oscillator modes involving a crystal or resonator (hs, hspll, lp or xt), the situation is somewhat different. since the oscillator may require a start-up time considerably longer than the fcsm sample clock time, a false clock failure may be detected. to prevent this, the internal oscillator block is automatically config- ured as the device clock and functions until the primary clock is stable (when the ost and pll timers have timed out). this is identical to two-speed start-up mode. once the primary clock is stable, the intosc returns to its role as the fscm source. as noted in section 28.4.1 ?special considerations for using two-speed start-up? , it is also possible to select another clock configuration and enter an alternate power-managed mode while waiting for the primary clock to become stable. when the new power- managed mode is selected, the primary clock is disabled. oscfif cm output device clock output sample clock failure detected oscillator failure note: the device clock is normally at a much higher frequency t han the sample clock. the relative frequencies in this example have been chosen for clarity. (q ) cm test cm test cm test note: the same logic that prevents false oscilla- tor failure interrupts on por, or wake from sleep, also prevents the detection of the oscillator?s failure to start at all following these events. this can be avoided by monitoring the osts bit and using a timing routine to determine if the oscillator is taking too long to start. even so, no oscillator failure interrupt will be flagged.
? 2011 microchip technology inc. ds39977d-page 481 pic18f66k80 family 28.6 program verification and code protection the user program memory is divided into four blocks. one of these is a boot block of 1 or 2 kbytes. the remainder of the memory is divided into blocks on binary boundaries. each of the blocks has three code protection bits associated with them. they are: ? code-protect bit (cpx) ? write-protect bit (wrtx) ? external block table read bit (ebtrx) figure 28-6 shows the program memory organization for 48, 64, 96 and 128 kbyte devices and the specific code protection bit associated with each block. the actual locations of the bits are summarized in table 28-4 . figure 28-6: code-protected program memory for the pic18f66k80 family 000000h 200000h 3fffffh 01ffffh note 1: sizes of memory areas are not to scale. 2: boot block size is determined by the bbsiz0 bit (config4l<4>). code memory unimplemented read as ? 0 ? configuration and id space device/memory size (1) address pic18fx6k80 pic18fx5k80 bbsiz = 1 bbsiz = 0 bbsiz = 1 bbsiz = 0 boot block 2kw boot block boot block 2kw boot block 0000h block 0 7kw block 0 3kw 0800h block 0 6kw block 0 2kw 1000h 1fffh block 1 4kw block 1 4kw 2000h 3fffh block 1 8kw block 1 8kw block 2 4kw block 2 4kw 4000h 5fffh block 3 4kw block 3 4kw 6000h 7fffh block 2 8kw block 2 8kw 8000h bfffh block 3 8kw block 3 8kw c000h ffffh 10000h 13fffh 14000h 17fffh 18000h 1bfffh 1c000h 1ffffh
pic18f66k80 family ds39977d-page 482 ? 2011 microchip technology inc. table 28-4: summary of code protection registers 28.6.1 program memory code protection the program memory may be read to, or written from, any location using the table read and table write instructions. the device id may be read with table reads. the configuration registers may be read and written with the table read and table write instructions. in normal execution mode, the cpx bits have no direct effect. cpx bits inhibit external reads and writes. a block of user memory may be protected from table writes if the wrtx configuration bit is ? 0 ?. the ebtrx bits control table reads. for a block of user memory with the ebtrx bit set to ? 0 ?, a table read instruction that executes from within that block is allowed to read. a table read instruction that executes from a location outside of that block is not allowed to read and will result in reading ? 0 ?s. figures 28-7 through 28-9 illustrate table write and table read protection. figure 28-7: table write (wrtx) disallowed file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 300008h config5l ? ? ? ? cp3 cp2 cp1 cp0 300009h config5h cpd cpb ? ? ? ? ? ? 30000ah config6l ? ? ? ? wrt3 wrt2 wrt1 wrt0 30000bh config6h wrtd wrtb wrtc ? ? ? ? ? 30000ch config7l ? ? ? ? ebtr3 ebtr2 ebtr1 ebtr0 30000dh config7h ? ebtrb ? ? ? ? ? ? legend: shaded cells are unimplemented. note: code protection bits may only be written to a ? 0 ? from a ? 1 ? state. it is not possible to write a ? 1 ? to a bit in the ? 0 ? state. code protection bits are only set to ? 1 ? by a full chip erase or block erase function. the full chip erase and block erase functions can only be initiated via icsp or an external programmer. refer to the device programming specification for more information. 000000h 0007ffh 000800h 003fffh 004000h 007fffh 008000h 00bfffh 00c000h 00ffffh wrtb, ebtrb = 11 wrt0, ebtr0 = 01 wrt1, ebtr1 = 11 wrt2, ebtr2 = 11 wrt3, ebtr3 = 11 tblwt* tblptr = 0008ffh pc = 003ffeh tblwt* pc = 00bffeh register values program memory configuration bit settings results: all table writes are disabled to blockn whenever wrtx = 0 .
? 2011 microchip technology inc. ds39977d-page 483 pic18f66k80 family figure 28-8: external block table read (ebtrx) disallowed figure 28-9: external block table read (ebtrx) allowed wrtb, ebtrb = 11 wrt0, ebtr0 = 10 wrt1, ebtr1 = 11 wrt2, ebtr2 = 11 wrt3, ebtr3 = 11 tblrd* tblptr = 0008ffh pc = 007ffeh results: all table reads from external blocks to blockn are disabled whenever ebtrx = 0 . the tablat register returns a value of ? 0 ?. register values program memory configuration bit settings 000000h 0007ffh 000800h 003fffh 004000h 007fffh 008000h 00bfffh 00c000h 00ffffh wrtb, ebtrb = 11 wrt0, ebtr0 = 10 wrt1, ebtr1 = 11 wrt2, ebtr2 = 11 wrt3, ebtr3 = 11 tblrd* tblptr = 0008ffh pc = 003ffeh register values program memory configuration bit settings results: table reads permitted within blockn, even when ebtrbx = 0 . the tablat register returns the value of the data at the location, tblptr. 000000h 0007ffh 000800h 003fffh 004000h 007fffh 008000h 00bfffh 00c000h 00ffffh
pic18f66k80 family ds39977d-page 484 ? 2011 microchip technology inc. 28.6.2 data eeprom code protection the entire data eeprom is protected from external reads and writes by two bits: cpd and wrtd. cpd inhibits external reads and writes of data eeprom. wrtd inhibits internal and external writes to data eeprom. the cpu can always read data eeprom under normal operation, regardless of the protection bit settings. 28.6.3 configuration register protection the configuration registers can be write-protected. the wrtc bit controls protection of the configuration registers. in normal execution mode, the wrtc bit is readable only. wrtc can only be written via icsp or an external programmer. 28.7 id locations eight memory locations (200000h-200007h) are designated as id locations, where the user can store checksum or other code identification numbers. these locations are both readable and writable during normal execution through the tblrd and tblwt instructions or during program/verify. the id locations can be read when the device is code-protected. 28.8 in-circuit serial programming the pic18f66k80 family of devices can be serially programmed while in the end application circuit. this is simply done with two lines for clock and data and three other lines for power, ground and the programming voltage. this allows customers to manufacture boards with unprogrammed devices and then program the microcontroller just before shipping the product. this also allows the most recent firmware or a custom firmware to be programmed. for the various programming modes, see the programming specification 28.9 in-circuit debugger when the debug configuration bit is programmed to a ? 0 ?, the in-circuit debugger functionality is enabled. this function allows simple debugging functions when used with mplab ? ide. when the microcontroller has this feature enabled, some resources are not available for general use. ta b l e 2 8 - 5 shows which resources are required by the background debugger. table 28-5: debugger resources to use the in-circuit debugger function of the micro- controller, the design must implement in-circuit serial programming connections to mclr /re3, v dd , v ss , rb7 and rb6. this will interface to the in-circuit debugger module available from microchip or one of the third-party development tool companies. i/o pins: rb6, rb7 stack: two levels program memory: 512 bytes data memory: 10 bytes
? 2011 microchip technology inc. ds39977d-page 485 pic18f66k80 family 29.0 instruction set summary the pic18f66k80 family of devices incorporates the standard set of 75 pic18 core instructions, as well as an extended set of 8 new instructions for the optimiza- tion of code that is recursive or that utilizes a software stack. the extended set is discussed later in this section. 29.1 standard instruction set the standard pic18 mcu instruction set adds many enhancements to the previous pic ? mcu instruction sets, while maintaining an easy migration from these pic mcu instruction sets. most instructions are a single program memory word (16 bits), but there are four instructions that require two program memory locations. each single-word instruction is a 16-bit word divided into an opcode, which specifies the instruction type and one or more operands, which further specify the operation of the instruction. the instruction set is highly orthogonal and is grouped into four basic categories: ? byte-oriented operations ? bit-oriented operations ? literal operations ? control operations the pic18 instruction set summary in table 29-2 lists byte-oriented , bit-oriented , literal and control operations. table 29-1 shows the opcode field descriptions. most byte-oriented instructions have three operands: 1. the file register (specified by ?f?) 2. the destination of the result (specified by ?d?) 3. the accessed memory (specified by ?a?) the file register designator, ?f?, specifies which file reg- ister is to be used by the instruction. the destination designator, ?d?, specifies where the result of the operation is to be placed. if ?d? is zero, the result is placed in the wreg register. if ?d? is one, the result is placed in the file register specified in the instruction. all bit-oriented instructions have three operands: 1. the file register (specified by ?f?) 2. the bit in the file register (specified by ?b?) 3. the accessed memory (specified by ?a?) the bit field designator, ?b?, selects the number of the bit affected by the operation, while the file register desig- nator, ?f?, represents the number of the file in which the bit is located. the literal instructions may use some of the following operands: ? a literal value to be loaded into a file register (specified by ?k?) ? the desired fsr register to load the literal value into (specified by ?f?) ? no operand required (specified by ???) the control instructions may use some of the following operands: ? a program memory address (specified by ?n?) ? the mode of the call or return instructions (specified by ?s?) ? the mode of the table read and table write instructions (specified by ?m?) ? no operand required (specified by ???) all instructions are a single word, except for four double-word instructions. these instructions were made double-word to contain the required information in 32 bits. in the second word, the 4 msbs are ? 1 ?s. if this second word is executed as an instruction (by itself), it will execute as a nop . all single-word instructions are executed in a single instruction cycle, unless a conditional test is true or the program counter is changed as a result of the instruc- tion. in these cases, the execution takes two instruction cycles with the additional instruction cycle(s) executed as a nop . the double-word instructions execute in two instruction cycles. one instruction cycle consists of four oscillator periods. thus, for an oscillator frequency of 4 mhz, the normal instruction execution time is 1 ? s. if a conditional test is true, or the program counter is changed as a result of an instruction, the instruction execution time is 2 ? s. two-word branch instructions (if true) would take 3 ? s. figure 29-1 shows the general formats that the instruc- tions can have. all examples use the convention ?nnh? to represent a hexadecimal number. the instruction set summary, shown in ta bl e 2 9 -2 , lists the standard instructions recognized by the microchip mpasm tm assembler. section 29.1.1 ?standard instruction set? provides a description of each instruction.
pic18f66k80 family ds39977d-page 486 ? 2011 microchip technology inc. table 29-1: opcode field descriptions field description a ram access bit: a = 0 : ram location in access ram (bsr register is ignored) a = 1 : ram bank is specified by bsr register bbb bit address within an 8-bit file register (0 to 7). bsr bank select register. used to select the current ram bank. c, dc, z, ov, n alu status bits: c arry, d igit c arry, z ero, ov erflow, n egative. d destination select bit: d = 0 : store result in wreg d = 1 : store result in file register f dest destination: either the wreg register or the specified register file location. f 8-bit register file address (00h to ffh), or 2-bit fsr designator (0h to 3h). f s 12-bit register file address (000h to fffh). this is the source address. f d 12-bit register file address (000h to fffh). this is the destination address. gie global interrupt enable bit. k literal field, constant data or label (may be either an 8-bit, 12-bit or a 20-bit value). label label name. mm the mode of the tblptr register for the table read and table write instructions. only used with table read and table write instructions: * no change to register (such as tblptr with table reads and writes) *+ post-increment register (such as tblptr with table reads and writes) *- post-decrement register (such as tblptr with table reads and writes) +* pre-increment register (such as tblptr with table reads and writes) n the relative address (2?s complement number) for relative branch instructions or the direct address for call/branch and return instructions. pc program counter. pcl program counter low byte. pch program counter high byte. pclath program counter high byte latch. pclatu program counter upper byte latch. pd power-down bit. prodh product of multiply high byte. prodl product of multiply low byte. s fast call/return mode select bit: s = 0 : do not update into/from shadow registers s = 1 : certain registers loaded into/from shadow registers (fast mode) tblptr 21-bit table pointer (points to a program memory location). tablat 8-bit table latch. to time-out bit. tos top-of-stack. u unused or unchanged. wdt watchdog timer. wreg working register (accumulator). x don?t care (? 0 ? or ? 1 ?). the assembler will generate code with x = 0 . it is the recommended form of use for compatibility with all microchip software tools. z s 7-bit offset value for indirect addressing of register files (source). z d 7-bit offset value for indirect addressing of register files (destination). { } optional argument. [text] indicates an indexed address. (text) the contents of text . [expr] specifies bit n of the register indicated by the pointer expr . ? assigned to. < > register bit field. ? in the set of. italics user-defined term (font is courier new).
? 2011 microchip technology inc. ds39977d-page 487 pic18f66k80 family figure 29-1: general format for instructions byte-oriented file register operations 15 10 9 8 7 0 d = 0 for result destination to be wreg register opcode d a f (file #) d = 1 for result destination to be file register (f) a = 0 to force access bank bit-oriented file register operations 15 12 11 9 8 7 0 opcode b (bit #) a f (file #) b = 3-bit position of bit in file register (f) literal operations 15 8 7 0 opcode k (literal) k = 8-bit immediate value byte to byte move operations (2-word) 15 12 11 0 opcode f (source file #) call , goto and branch operations 15 8 7 0 opcode n<7:0> (literal) n = 20-bit immediate value a = 1 for bsr to select bank f = 8-bit file register address a = 0 to force access bank a = 1 for bsr to select bank f = 8-bit file register address 15 12 11 0 1111 n<19:8> (literal) 15 12 11 0 1111 f (destination file #) f = 12-bit file register address control operations example instruction addwf myreg, w, b movff myreg1, myreg2 bsf myreg, bit, b movlw 7fh goto label 15 8 7 0 opcode s n<7:0> (literal) 15 12 11 0 1111 n<19:8> (literal) call myfunc 15 11 10 0 opcode n<10:0> (literal) s = fast bit bra myfunc 15 8 7 0 opcode n<7:0> (literal) bc myfunc
pic18f66k80 family ds39977d-page 488 ? 2011 microchip technology inc. table 29-2: pic18f66k80 family instruction set mnemonic, operands description cycles 16-bit instruction word status affected notes msb lsb byte-oriented operations addwf addwfc andwf clrf comf cpfseq cpfsgt cpfslt decf decfsz dcfsnz incf incfsz infsnz iorwf movf movff movwf mulwf negf rlcf rlncf rrcf rrncf setf subfwb subwf subwfb swapf tstfsz xorwf f, d, a f, d, a f, d, a f, a f, d, a f, a f, a f, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f s , f d f, a f, a f, a f, d, a f, d, a f, d, a f, d, a f, a f, d, a f, d, a f, d, a f, d, a f, a f, d, a add wreg and f add wreg and carry bit to f and wreg with f clear f complement f compare f with wreg, skip = compare f with wreg, skip > compare f with wreg, skip < decrement f decrement f, skip if 0 decrement f, skip if not 0 increment f increment f, skip if 0 increment f, skip if not 0 inclusive or wreg with f move f move f s (source) to 1st word f d (destination) 2nd word move wreg to f multiply wreg with f negate f rotate left f through carry rotate left f (no carry) rotate right f through carry rotate right f (no carry) set f subtract f from wreg with borrow subtract wreg from f subtract wreg from f with borrow swap nibbles in f test f, skip if 0 exclusive or wreg with f 1 1 1 1 1 1 (2 or 3) 1 (2 or 3) 1 (2 or 3) 1 1 (2 or 3) 1 (2 or 3) 1 1 (2 or 3) 1 (2 or 3) 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 (2 or 3) 1 0010 0010 0001 0110 0001 0110 0110 0110 0000 0010 0100 0010 0011 0100 0001 0101 1100 1111 0110 0000 0110 0011 0100 0011 0100 0110 0101 0101 0101 0011 0110 0001 01da 00da 01da 101a 11da 001a 010a 000a 01da 11da 11da 10da 11da 10da 00da 00da ffff ffff 111a 001a 110a 01da 01da 00da 00da 100a 01da 11da 10da 10da 011a 10da ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff c, dc, z, ov, n c, dc, z, ov, n z, n z z, n none none none c, dc, z, ov, n none none c, dc, z, ov, n none none z, n z, n none none none c, dc, z, ov, n c, z, n z, n c, z, n z, n none c, dc, z, ov, n c, dc, z, ov, n c, dc, z, ov, n none none z, n 1, 2 1, 2 1,2 2 1, 2 4 4 1, 2 1, 2, 3, 4 1, 2, 3, 4 1, 2 1, 2, 3, 4 4 1, 2 1, 2 1 1, 2 1, 2 1, 2 1, 2 4 1, 2 note 1: when a port register is modified as a function of itself (e.g., movf portb, 1, 0 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as an input and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tmr0 register (and, where applicable, d = 1 ), the prescaler will be cleared if assigned. 3: if the program counter (pc) is modified or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop . 4: some instructions are two-word instructions. the second word of these instructions will be executed as a nop unless the first word of the instruction retrieves the information embedded in these 16 bits. this ensures that all program memory locations have a valid instruction.
? 2011 microchip technology inc. ds39977d-page 489 pic18f66k80 family bit-oriented operations bcf bsf btfsc btfss btg f, b, a f, b, a f, b, a f, b, a f, b, a bit clear f bit set f bit test f, skip if clear bit test f, skip if set bit toggle f 1 1 1 (2 or 3) 1 (2 or 3) 1 1001 1000 1011 1010 0111 bbba bbba bbba bbba bbba ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff none none none none none 1, 2 1, 2 3, 4 3, 4 1, 2 control operations bc bn bnc bnn bnov bnz bov bra bz call clrwdt daw goto nop nop pop push rcall reset retfie retlw return sleep n n n n n n n n n n, s ? ? n ? ? ? ? n s k s ? branch if carry branch if negative branch if not carry branch if not negative branch if not overflow branch if not zero branch if overflow branch unconditionally branch if zero call subroutine 1st word 2nd word clear watchdog timer decimal adjust wreg go to address 1st word 2nd word no operation no operation pop top of return stack (tos) push top of return stack (tos) relative call software device reset return from interrupt enable return with literal in wreg return from subroutine go into standby mode 1 (2) 1 (2) 1 (2) 1 (2) 1 (2) 1 (2) 1 (2) 2 1 (2) 2 1 1 2 1 1 1 1 2 1 2 2 2 1 1110 1110 1110 1110 1110 1110 1110 1101 1110 1110 1111 0000 0000 1110 1111 0000 1111 0000 0000 1101 0000 0000 0000 0000 0000 0010 0110 0011 0111 0101 0001 0100 0nnn 0000 110s kkkk 0000 0000 1111 kkkk 0000 xxxx 0000 0000 1nnn 0000 0000 1100 0000 0000 nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn kkkk kkkk 0000 0000 kkkk kkkk 0000 xxxx 0000 0000 nnnn 1111 0001 kkkk 0001 0000 nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn kkkk kkkk 0100 0111 kkkk kkkk 0000 xxxx 0110 0101 nnnn 1111 000s kkkk 001s 0011 none none none none none none none none none none to , pd c none none none none none none all gie/gieh, peie/giel none none to , pd 4 table 29-2: pic18f66k80 family instruction set (continued) mnemonic, operands description cycles 16-bit instruction word status affected notes msb lsb note 1: when a port register is modified as a function of itself (e.g., movf portb, 1, 0 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as an input and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tmr0 register (and, where applicable, d = 1 ), the prescaler will be cleared if assigned. 3: if the program counter (pc) is modified or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop . 4: some instructions are two-word instructions. the second word of these instructions will be executed as a nop unless the first word of the instruction retrieves the information embedded in these 16 bits. this ensures that all program memory locations have a valid instruction.
pic18f66k80 family ds39977d-page 490 ? 2011 microchip technology inc. literal operations addlw andlw iorlw lfsr movlb movlw mullw retlw sublw xorlw k k k f, k k k k k k k add literal and wreg and literal with wreg inclusive or literal with wreg move literal (12-bit) 2nd word to fsr(f) 1st word move literal to bsr<3:0> move literal to wreg multiply literal with wreg return with literal in wreg subtract wreg from literal exclusive or literal with wreg 1 1 1 2 1 1 1 2 1 1 0000 0000 0000 1110 1111 0000 0000 0000 0000 0000 0000 1111 1011 1001 1110 0000 0001 1110 1101 1100 1000 1010 kkkk kkkk kkkk 00ff kkkk 0000 kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk c, dc, z, ov, n z, n z, n none none none none none c, dc, z, ov, n z, n data memory ? program memory operations tblrd* tblrd*+ tblrd*- tblrd+* tblwt* tblwt*+ tblwt*- tblwt+* table read table read with post-increment table read with post-decrement table read with pre-increment table write table write with post-increment table write with post-decrement table write with pre-increment 2 2 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 1000 1001 1010 1011 1100 1101 1110 1111 none none none none none none none none table 29-2: pic18f66k80 family instruction set (continued) mnemonic, operands description cycles 16-bit instruction word status affected notes msb lsb note 1: when a port register is modified as a function of itself (e.g., movf portb, 1, 0 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as an input and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tmr0 register (and, where applicable, d = 1 ), the prescaler will be cleared if assigned. 3: if the program counter (pc) is modified or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop . 4: some instructions are two-word instructions. the second word of these instructions will be executed as a nop unless the first word of the instruction retrieves the information embedded in these 16 bits. this ensures that all program memory locations have a valid instruction.
? 2011 microchip technology inc. ds39977d-page 491 pic18f66k80 family 29.1.1 standard instruction set addlw add literal to w syntax: addlw k operands: 0 ? k ? 255 operation: (w) + k ? w status affected: n, ov, c, dc, z encoding: 0000 1111 kkkk kkkk description: the contents of w are added to the 8-bit literal ?k? and t he result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: addlw 15h before instruction w = 10h after instruction w = 25h addwf add w to f syntax: addwf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (w) + (f) ? dest status affected: n, ov, c, dc, z encoding: 0010 01da ffff ffff description: add w to register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: addwf reg, 0, 0 before instruction w = 17h reg = 0c2h after instruction w = 0d9h reg = 0c2h note: all pic18 instructions may take an optional label argument preceding the instruction mnemonic for use in symbolic addressing. if a label is used, the instruction format then becomes: {label} instruction argument(s).
pic18f66k80 family ds39977d-page 492 ? 2011 microchip technology inc. addwfc add w and carry bit to f syntax: addwfc f {,d {,a}} operands: 0 ? f ? 255 d ?? [0,1] a ?? [0,1] operation: (w) + (f) + (c) ? dest status affected: n,ov, c, dc, z encoding: 0010 00da ffff ffff description: add w, the carry flag and data memory location ?f?. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed in data memory location ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: addwfc reg, 0, 1 before instruction carry bit = 1 reg = 02h w=4dh after instruction carry bit = 0 reg = 02h w = 50h andlw and literal with w syntax: andlw k operands: 0 ? k ? 255 operation: (w) .and. k ? w status affected: n, z encoding: 0000 1011 kkkk kkkk description: the contents of w are anded with the 8-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: andlw 05fh before instruction w=a3h after instruction w = 03h
? 2011 microchip technology inc. ds39977d-page 493 pic18f66k80 family andwf and w with f syntax: andwf f {,d {,a}} operands: 0 ? f ? 255 d ?? [0,1] a ?? [0,1] operation: (w) .and. (f) ? dest status affected: n, z encoding: 0001 01da ffff ffff description: the contents of w are anded with register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: andwf reg, 0, 0 before instruction w = 17h reg = c2h after instruction w = 02h reg = c2h bc branch if carry syntax: bc n operands: -128 ? n ? 127 operation: if carry bit is ? 1 ?, (pc) + 2 + 2n ? pc status affected: none encoding: 1110 0010 nnnn nnnn description: if the carry bit is ? 1 ?, then the program will branch. the 2?s complement number, ?2n?, is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bc 5 before instruction pc = address (here) after instruction if carry = 1 ; pc = address (here + 12) if carry = 0 ; pc = address (here + 2)
pic18f66k80 family ds39977d-page 494 ? 2011 microchip technology inc. bcf bit clear f syntax: bcf f, b {,a} operands: 0 ? f ? 255 0 ? b ? 7 a ?? [0,1] operation: 0 ? f status affected: none encoding: 1001 bbba ffff ffff description: bit ?b? in register ?f? is cleared. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: bcf flag_reg, 7, 0 before instruction flag_reg = c7h after instruction flag_reg = 47h bn branch if negative syntax: bn n operands: -128 ? n ? 127 operation: if negative bit is ? 1 ?, (pc) + 2 + 2n ? pc status affected: none encoding: 1110 0110 nnnn nnnn description: if the negative bit is ? 1 ?, then the program will branch. the 2?s complement number, ?2n?, is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bn jump before instruction pc = address (here) after instruction if negative = 1 ; pc = address (jump) if negative = 0 ; pc = address (here + 2)
? 2011 microchip technology inc. ds39977d-page 495 pic18f66k80 family bnc branch if not carry syntax: bnc n operands: -128 ? n ? 127 operation: if carry bit is ? 0 ?, (pc) + 2 + 2n ? pc status affected: none encoding: 1110 0011 nnnn nnnn description: if the carry bit is ? 0 ?, then the program will branch. the 2?s complement number, ?2n?, is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bnc jump before instruction pc = address (here) after instruction if carry = 0 ; pc = address (jump) if carry = 1 ; pc = address (here + 2) bnn branch if not negative syntax: bnn n operands: -128 ? n ? 127 operation: if negative bit is ? 0 ?, (pc) + 2 + 2n ? pc status affected: none encoding: 1110 0111 nnnn nnnn description: if the negative bit is ? 0 ?, then the program will branch. the 2?s complement number, ?2n?, is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bnn jump before instruction pc = address (here) after instruction if negative = 0 ; pc = address (jump) if negative = 1 ; pc = address (here + 2)
pic18f66k80 family ds39977d-page 496 ? 2011 microchip technology inc. bnov branch if not overflow syntax: bnov n operands: -128 ? n ? 127 operation: if overflow bit is ? 0 ?, (pc) + 2 + 2n ? pc status affected: none encoding: 1110 0101 nnnn nnnn description: if the overflow bit is ? 0 ?, then the program will branch. the 2?s complement number, ?2n?, is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bnov jump before instruction pc = address (here) after instruction if overflow = 0 ; pc = address (jump) if overflow = 1 ; pc = address (here + 2) bnz branch if not zero syntax: bnz n operands: -128 ? n ? 127 operation: if zero bit is ? 0 ?, (pc) + 2 + 2n ? pc status affected: none encoding: 1110 0001 nnnn nnnn description: if the zero bit is ? 0 ?, then the program will branch. the 2?s complement number, ?2n?, is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bnz jump before instruction pc = address (here) after instruction if zero = 0 ; pc = address (jump) if zero = 1 ; pc = address (here + 2)
? 2011 microchip technology inc. ds39977d-page 497 pic18f66k80 family bra unconditional branch syntax: bra n operands: -1024 ? n ? 1023 operation: (pc) + 2 + 2n ? pc status affected: none encoding: 1101 0nnn nnnn nnnn description: add the 2?s complement number, ?2n?, to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is a two-cycle instruction. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation example: here bra jump before instruction pc = address (here) after instruction pc = address (jump) bsf bit set f syntax: bsf f, b {,a} operands: 0 ? f ? 255 0 ? b ? 7 a ?? [0,1] operation: 1 ? f status affected: none encoding: 1000 bbba ffff ffff description: bit ?b? in register ?f? is set. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: bsf flag_reg, 7, 1 before instruction flag_reg = 0ah after instruction flag_reg = 8ah
pic18f66k80 family ds39977d-page 498 ? 2011 microchip technology inc. btfsc bit test file, skip if clear syntax: btfsc f, b {,a} operands: 0 ? f ? 255 0 ? b ? 7 a ?? [0,1] operation: skip if (f) = 0 status affected: none encoding: 1011 bbba ffff ffff description: if bit ?b? in register ?f? is ? 0 ?, then the next instruction is skipped. if bit ?b? is ? 0 ?, then the next instruction fetched during the current instruction execution is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here false true btfsc : : flag, 1, 0 before instruction pc = address (here) after instruction if flag<1> = 0 ; pc = address (true) if flag<1> = 1 ; pc = address (false) btfss bit test file, skip if set syntax: btfss f, b {,a} operands: 0 ? f ? 255 0 ? b < 7 a ?? [0,1] operation: skip if (f) = 1 status affected: none encoding: 1010 bbba ffff ffff description: if bit ?b? in register ?f? is ? 1 ?, then the next instruction is skipped. if bit ?b? is ? 1 ?, then the next instruction fetched during the current instruction execution is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here false true btfss : : flag, 1, 0 before instruction pc = address (here) after instruction if flag<1> = 0 ; pc = address (false) if flag<1> = 1 ; pc = address (true)
? 2011 microchip technology inc. ds39977d-page 499 pic18f66k80 family btg bit toggle f syntax: btg f, b {,a} operands: 0 ? f ? 255 0 ? b < 7 a ?? [0,1] operation: (f ) ? f status affected: none encoding: 0111 bbba ffff ffff description: bit ?b? in data memory location ?f? is inverted. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: btg portc, 4, 0 before instruction: portc = 0111 0101 [75h] after instruction: portc = 0110 0101 [65h] bov branch if overflow syntax: bov n operands: -128 ? n ? 127 operation: if overflow bit is ? 1 ?, (pc) + 2 + 2n ? pc status affected: none encoding: 1110 0100 nnnn nnnn description: if the overflow bit is ? 1 ?, then the program will branch. the 2?s complement number, ?2n?, is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bov jump before instruction pc = address (here) after instruction if overflow = 1 ; pc = address (jump) if overflow = 0 ; pc = address (here + 2)
pic18f66k80 family ds39977d-page 500 ? 2011 microchip technology inc. bz branch if zero syntax: bz n operands: -128 ? n ? 127 operation: if zero bit is ? 1 ?, (pc) + 2 + 2n ? pc status affected: none encoding: 1110 0000 nnnn nnnn description: if the zero bit is ? 1 ?, then the program will branch. the 2?s complement number, ?2n?, is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bz jump before instruction pc = address (here) after instruction if zero = 1 ; pc = address (jump) if zero = 0 ; pc = address (here + 2) call subroutine call syntax: call k {,s} operands: 0 ? k ? 1048575 s ?? [0,1] operation: (pc) + 4 ? tos, k ? pc<20:1>; if s = 1 (w) ? ws, (status) ? statuss, (bsr) ? bsrs status affected: none encoding: 1st word (k<7:0>) 2nd word(k<19:8>) 1110 1111 110s k 19 kkk k 7 kkk kkkk kkkk 0 kkkk 8 description: subroutine call of entire 2-mbyte memory range. first, return address (pc+ 4) is pushed onto the return stack. if ?s? = 1 , the w, status and bsr registers are also pushed into their respective shadow registers, ws, statuss and bsrs. if ?s? = 0 , no update occurs (default). then, the 20-bit value ?k? is loaded into pc<20:1>. call is a two-cycle instruction. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k?<7:0>, push pc to stack read literal ?k?<19:8>, write to pc no operation no operation no operation no operation example: here call there,1 before instruction pc = address (here) after instruction pc = address (there) tos = address (here + 4) ws = w bsrs = bsr statuss = status
? 2011 microchip technology inc. ds39977d-page 501 pic18f66k80 family clrf clear f syntax: clrf f {,a} operands: 0 ? f ? 255 a ?? [0,1] operation: 000h ? f, 1 ? z status affected: z encoding: 0110 101a ffff ffff description: clears the contents of the specified register. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: clrf flag_reg,1 before instruction flag_reg = 5ah after instruction flag_reg = 00h clrwdt clear watchdog timer syntax: clrwdt operands: none operation: 000h ? wdt, 000h ? wdt postscaler, 1 ? to , 1 ? pd status affected: to , pd encoding: 0000 0000 0000 0100 description: clrwdt instruction resets the watchdog timer. it also resets the postscaler of the wdt. status bits, to and pd , are set. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation process data no operation example: clrwdt before instruction wdt counter = ? after instruction wdt counter = 00h wdt postscaler = 0 to = 1 pd = 1
pic18f66k80 family ds39977d-page 502 ? 2011 microchip technology inc. comf complement f syntax: comf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: f ? dest status affected: n, z encoding: 0001 11da ffff ffff description: the contents of register ?f? are complemented. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: comf reg, 0, 0 before instruction reg = 13h after instruction reg = 13h w=ech cpfseq compare f with w, skip if f = w syntax: cpfseq f {,a} operands: 0 ? f ? 255 a ? [0,1] operation: (f) ? (w), skip if (f) = (w) (unsigned comparison) status affected: none encoding: 0110 001a ffff ffff description: compares the contents of data memory location ?f? to the contents of w by performing an unsigned subtraction. if ?f? = w , then the fetched instruction is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here cpfseq reg, 0 nequal : equal : before instruction pc address = here w=? reg = ? after instruction if reg = w; pc = address (equal) if reg ? w; pc = address (nequal)
? 2011 microchip technology inc. ds39977d-page 503 pic18f66k80 family cpfsgt compare f with w, skip if f > w syntax: cpfsgt f {,a} operands: 0 ? f ? 255 a ? [0,1] operation: (f) ? ?? w), skip if (f) > (w) (unsigned comparison) status affected: none encoding: 0110 010a ffff ffff description: compares the contents of data memory location ?f? to the contents of the w by performing an unsigned subtraction. if the contents of ?f? are greater than the contents of wreg , then the fetched instruction is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here cpfsgt reg, 0 ngreater : greater : before instruction pc = address (here) w= ? after instruction if reg ? w; pc = address (greater) if reg ? w; pc = address (ngreater) cpfslt compare f with w, skip if f < w syntax: cpfslt f {,a} operands: 0 ? f ? 255 a ? [0,1] operation: (f) ? ?? w), skip if (f) < (w) (unsigned comparison) status affected: none encoding: 0110 000a ffff ffff description: compares the contents of data memory location ?f? to the contents of w by performing an unsigned subtraction. if the contents of ?f? are less than the contents of w, then the fetched instruction is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here cpfslt reg, 1 nless : less : before instruction pc = address (here) w= ? after instruction if reg < w; pc = address (less) if reg ? w; pc = address (nless)
pic18f66k80 family ds39977d-page 504 ? 2011 microchip technology inc. daw decimal adjust w register syntax: daw operands: none operation: if [w<3:0> > 9] or [dc = 1 ], then (w<3:0>) + 6 ? w<3:0>; else (w<3:0>) ? w<3:0> if [w<7:4> > 9] or [c = 1 ], then (w<7:4>) + 6 ? w<7:4>; c = ? 1 else (w<7:4>) ? w<7:4> status affected: c encoding: 0000 0000 0000 0111 description: daw adjusts the eight-bit value in w, resulting from the earlier addition of two variables (each in packed bcd format) and produces a correct packed bcd result. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register w process data write w example 1: daw before instruction w=a5h c= 0 dc = 0 after instruction w = 05h c= 1 dc = 0 example 2: before instruction w=ceh c= 0 dc = 0 after instruction w = 34h c= 1 dc = 0 decf decrement f syntax: decf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) ? 1 ? dest status affected: c, dc, n, ov, z encoding: 0000 01da ffff ffff description: decrement register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: decf cnt, 1, 0 before instruction cnt = 01h z= 0 after instruction cnt = 00h z= 1
? 2011 microchip technology inc. ds39977d-page 505 pic18f66k80 family decfsz decrement f, skip if 0 syntax: decfsz f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) ? 1 ? dest, skip if result = 0 status affected: none encoding: 0010 11da ffff ffff description: the contents of register ?f? are decremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if the result is ? 0 ?, the next instruction which is already fetched is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here decfsz cnt, 1, 1 goto loop continue before instruction pc = address (here) after instruction cnt = cnt ? 1 if cnt = 0 ; pc = address (continue) if cnt ? 0 ; pc = address (here + 2) dcfsnz decrement f, skip if not 0 syntax: dcfsnz f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) ? 1 ? dest, skip if result ? 0 status affected: none encoding: 0100 11da ffff ffff description: the contents of register ?f? are decremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if the result is not ? 0 ?, the next instruction which is already fetched is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here dcfsnz temp, 1, 0 zero : nzero : before instruction temp = ? after instruction temp = temp ? 1, if temp = 0 ; pc = address (zero) if temp ? 0 ; pc = address (nzero)
pic18f66k80 family ds39977d-page 506 ? 2011 microchip technology inc. goto unconditional branch syntax: goto k operands: 0 ? k ? 1048575 operation: k ? pc<20:1> status affected: none encoding: 1st word (k<7:0>) 2nd word(k<19:8>) 1110 1111 1111 k 19 kkk k 7 kkk kkkk kkkk 0 kkkk 8 description: goto allows an unconditional branch anywhere within entire 2-mbyte memory range. the 20-bit value ?k? is loaded into pc<20:1>. goto is always a two-cycle instruction. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k?<7:0>, no operation read literal ?k?<19:8>, write to pc no operation no operation no operation no operation example: goto there after instruction pc = address (there) incf increment f syntax: incf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) + 1 ? dest status affected: c, dc, n, ov, z encoding: 0010 10da ffff ffff description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: incf cnt, 1, 0 before instruction cnt = ffh z= 0 c=? dc = ? after instruction cnt = 00h z= 1 c= 1 dc = 1
? 2011 microchip technology inc. ds39977d-page 507 pic18f66k80 family incfsz increment f, skip if 0 syntax: incfsz f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) + 1 ? dest, skip if result = 0 status affected: none encoding: 0011 11da ffff ffff description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f?. (default) if the result is ? 0 ?, the next instruction which is already fetched is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here incfsz cnt, 1, 0 nzero : zero : before instruction pc = address (here) after instruction cnt = cnt + 1 if cnt = 0 ; pc = address (zero) if cnt ? 0 ; pc = address (nzero) infsnz increment f, skip if not 0 syntax: infsnz f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) + 1 ? dest, skip if result ? 0 status affected: none encoding: 0100 10da ffff ffff description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if the result is not ? 0 ?, the next instruction which is already fetched is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here infsnz reg, 1, 0 zero nzero before instruction pc = address (here) after instruction reg = reg + 1 if reg ? 0 ; pc = address (nzero) if reg = 0 ; pc = address (zero)
pic18f66k80 family ds39977d-page 508 ? 2011 microchip technology inc. iorlw inclusive or literal with w syntax: iorlw k operands: 0 ? k ? 255 operation: (w) .or. k ? w status affected: n, z encoding: 0000 1001 kkkk kkkk description: the contents of w are ored with the eight-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: iorlw 35h before instruction w=9ah after instruction w=bfh iorwf inclusive or w with f syntax: iorwf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (w) .or. (f) ? dest status affected: n, z encoding: 0001 00da ffff ffff description: inclusive or w with register ?f?. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: iorwf result, 0, 1 before instruction result = 13h w = 91h after instruction result = 13h w = 93h
? 2011 microchip technology inc. ds39977d-page 509 pic18f66k80 family lfsr load fsr syntax: lfsr f, k operands: 0 ? f ? 2 0 ? k ? 4095 operation: k ? fsrf status affected: none encoding: 1110 1111 1110 0000 00ff k 7 kkk k 11 kkk kkkk description: the 12-bit literal ?k? is loaded into the file select register pointed to by ?f?. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k? msb process data write literal ?k? msb to fsrfh decode read literal ?k? lsb process data write literal ?k? to fsrfl example: lfsr 2, 3abh after instruction fsr2h = 03h fsr2l = abh movf move f syntax: movf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: f ? dest status affected: n, z encoding: 0101 00da ffff ffff description: the contents of register ?f? are moved to a destination dependent upon the status of ?d?. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). location ?f? can be anywhere in the 256-byte bank. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write w example: movf reg, 0, 0 before instruction reg = 22h w=ffh after instruction reg = 22h w = 22h
pic18f66k80 family ds39977d-page 510 ? 2011 microchip technology inc. movff move f to f syntax: movff f s ,f d operands: 0 ? f s ? 4095 0 ? f d ? 4095 operation: (f s ) ? f d status affected: none encoding: 1st word (source) 2nd word (destin.) 1100 1111 ffff ffff ffff ffff ffff s ffff d description: the contents of source register ?f s ? are moved to destination register ?f d ?. location of source ?f s ? can be anywhere in the 4096-byte data space (000h to fffh) and location of destination ?f d ? can also be anywhere from 000h to fffh. either source or destination can be w (a useful special situation). movff is particularly useful for transferring a data memory location to a peripheral register (such as the transmit buffer or an i/o port). the movff instruction cannot use the pcl, tosu, tosh or tosl as the destination register words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read register ?f? (src) process data no operation decode no operation no dummy read no operation write register ?f? (dest) example: movff reg1, reg2 before instruction reg1 = 33h reg2 = 11h after instruction reg1 = 33h reg2 = 33h movlb move literal to low nibble in bsr syntax: movlw k operands: 0 ? k ? 255 operation: k ? bsr status affected: none encoding: 0000 0001 kkkk kkkk description: the eight-bit literal ?k? is loaded into the bank select register (bsr). the value of bsr<7:4> always remains ? 0 ? regardless of the value of k 7 :k 4 . words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write literal ?k? to bsr example: movlb 5 before instruction bsr register = 02h after instruction bsr register = 05h
? 2011 microchip technology inc. ds39977d-page 511 pic18f66k80 family movlw move literal to w syntax: movlw k operands: 0 ? k ? 255 operation: k ? w status affected: none encoding: 0000 1110 kkkk kkkk description: the eight-bit literal ?k? is loaded into w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: movlw 5ah after instruction w=5ah movwf move w to f syntax: movwf f {,a} operands: 0 ? f ? 255 a ? [0,1] operation: (w) ? f status affected: none encoding: 0110 111a ffff ffff description: move data from w to register ?f?. location ?f? can be anywhere in the 256-byte bank. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: movwf reg, 0 before instruction w=4fh reg = ffh after instruction w=4fh reg = 4fh
pic18f66k80 family ds39977d-page 512 ? 2011 microchip technology inc. mullw multiply literal with w syntax: mullw k operands: 0 ? k ? 255 operation: (w) x k ? prodh:prodl status affected: none encoding: 0000 1101 kkkk kkkk description: an unsigned multiplication is carried out between the contents of w and the 8-bit literal ?k?. the 16-bit result is placed in the prodh:prodl register pair. prodh contains the high byte. w is unchanged. none of the status flags are affected. note that neither overflow nor carry is possible in this operation. a zero result is possible but not detected. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write registers prodh: prodl example: mullw 0c4h before instruction w=e2h prodh = ? prodl = ? after instruction w=e2h prodh = adh prodl = 08h mulwf multiply w with f syntax: mulwf f {,a} operands: 0 ? f ? 255 a ? [0,1] operation: (w) x (f) ? prodh:prodl status affected: none encoding: 0000 001a ffff ffff description: an unsigned multiplication is carried out between the contents of w and the register file location ?f?. the 16-bit result is stored in the prodh:prodl register pair. prodh contains the high byte. both w and ?f? are unchanged. none of the status flags are affected. note that neither overflow nor carry is possible in this operation. a zero result is possible but not detected. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write registers prodh: prodl example: mulwf reg, 1 before instruction w=c4h reg = b5h prodh = ? prodl = ? after instruction w=c4h reg = b5h prodh = 8ah prodl = 94h
? 2011 microchip technology inc. ds39977d-page 513 pic18f66k80 family negf negate f syntax: negf f {,a} operands: 0 ? f ? 255 a ? [0,1] operation: (f ) + 1 ? f status affected: n, ov, c, dc, z encoding: 0110 110a ffff ffff description: location ?f? is negated using two?s complement. the result is placed in the data memory location ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: negf reg, 1 before instruction reg = 0011 1010 [3ah] after instruction reg = 1100 0110 [c6h] nop no operation syntax: nop operands: none operation: no operation status affected: none encoding: 0000 1111 0000 xxxx 0000 xxxx 0000 xxxx description: no operation. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation no operation no operation example: none.
pic18f66k80 family ds39977d-page 514 ? 2011 microchip technology inc. pop pop top of return stack syntax: pop operands: none operation: (tos) ? bit bucket status affected: none encoding: 0000 0000 0000 0110 description: the tos value is pulled off the return stack and is discarded. the tos value then becomes the previous value that was pushed onto the return stack. this instruction is provided to enable the user to properly manage the return stack to incorporate a software stack. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation pop tos value no operation example: pop goto new before instruction tos = 0031a2h stack (1 level down) = 014332h after instruction tos = 014332h pc = new push push top of return stack syntax: push operands: none operation: (pc + 2) ? tos status affected: none encoding: 0000 0000 0000 0101 description: the pc + 2 is pushed onto the top of the return stack. the previous tos value is pushed down on the stack. this instruction allows implementing a software stack by modifying tos and then pushing it onto the return stack. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode push pc + 2 onto return stack no operation no operation example: push before instruction tos = 345ah pc = 0124h after instruction pc = 0126h tos = 0126h stack (1 level down) = 345ah
? 2011 microchip technology inc. ds39977d-page 515 pic18f66k80 family rcall relative call syntax: rcall n operands: -1024 ? n ? 1023 operation: (pc) + 2 ? tos, (pc) + 2 + 2n ? pc status affected: none encoding: 1101 1nnn nnnn nnnn description: subroutine call with a jump up to 1k from the current location. first, return address (pc + 2) is pushed onto the stack. then, add the 2?s complement number ?2n? to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is a two-cycle instruction. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?n? push pc to stack process data write to pc no operation no operation no operation no operation example: here rcall jump before instruction pc = address (here) after instruction pc = address (jump) tos = address (here + 2) reset reset syntax: reset operands: none operation: reset all registers and flags that are affected by a mclr reset. status affected: all encoding: 0000 0000 1111 1111 description: this instruction provides a way to execute a mclr reset in software. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode start reset no operation no operation example: reset after instruction registers = reset value flags* = reset value
pic18f66k80 family ds39977d-page 516 ? 2011 microchip technology inc. retfie return from interrupt syntax: retfie {s} operands: s ? [0,1] operation: (tos) ? pc, 1 ? gie/gieh or peie/giel; if s = 1 , (ws) ? w, (statuss) ? status, (bsrs) ? bsr, pclatu, pclath are unchanged status affected: gie/gieh, peie/giel. encoding: 0000 0000 0001 000s description: return from interrupt. stack is popped and top-of-stack (tos) is loaded into the pc. interrupts are enabled by setting either the high or low-priority global interrupt enable bit. if ?s? = 1 , the contents of the shadow registers ws, statuss and bsrs are loaded into their corresponding registers w, status and bsr. if ?s? = 0 , no update of these registers occurs (default). words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation no operation pop pc from stack set gieh or giel no operation no operation no operation no operation example: retfie 1 after interrupt pc = tos w=ws bsr = bsrs status = statuss gie/gieh, peie/giel = 1 retlw return literal to w syntax: retlw k operands: 0 ? k ? 255 operation: k ? w, (tos) ? pc, pclatu, pclath are unchanged status affected: none encoding: 0000 1100 kkkk kkkk description: w is loaded with the eight-bit literal ?k?. the program counter is loaded from the top of the stack (the return address). the high address latch (pclath) remains unchanged. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data pop pc from stack, write to w no operation no operation no operation no operation example: call table ; w contains table ; offset value ; w now has ; table value : table addwf pcl ; w = offset retlw k0 ; begin table retlw k1 ; : : retlw kn ; end of table before instruction w = 07h after instruction w = value of kn
? 2011 microchip technology inc. ds39977d-page 517 pic18f66k80 family return return from subroutine syntax: return {s} operands: s ? [0,1] operation: (tos) ? pc; if s = 1 , (ws) ? w, (statuss) ? status, (bsrs) ? bsr, pclatu, pclath are unchanged status affected: none encoding: 0000 0000 0001 001s description: return from subroutine. the stack is popped and the top of the stack (tos) is loaded into the program counter. if ?s? = 1 , the contents of the shadow registers ws, statuss and bsrs are loaded into their corresponding registers w, status and bsr. if ?s? = 0 , no update of these registers occurs (default). words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation process data pop pc from stack no operation no operation no operation no operation example: return after instruction: pc = tos rlcf rotate left f through carry syntax: rlcf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) ? dest, (f<7>) ? c, (c) ? dest<0> status affected: c, n, z encoding: 0011 01da ffff ffff description: the contents of register ?f? are rotated one bit to the left through the carry flag. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: rlcf reg, 0, 0 before instruction reg = 1110 0110 c= 0 after instruction reg = 1110 0110 w = 1100 1100 c= 1 c register f
pic18f66k80 family ds39977d-page 518 ? 2011 microchip technology inc. rlncf rotate left f (no carry) syntax: rlncf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) ? dest, (f<7>) ? dest<0> status affected: n, z encoding: 0100 01da ffff ffff description: the contents of register ?f? are rotated one bit to the left. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: rlncf reg, 1, 0 before instruction reg = 1010 1011 after instruction reg = 0101 0111 register f rrcf rotate right f through carry syntax: rrcf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) ? dest, (f<0>) ? c, (c) ? dest<7> status affected: c, n, z encoding: 0011 00da ffff ffff description: the contents of register ?f? are rotated one bit to the right through the carry flag. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: rrcf reg, 0, 0 before instruction reg = 1110 0110 c= 0 after instruction reg = 1110 0110 w = 0111 0011 c= 0 c register f
? 2011 microchip technology inc. ds39977d-page 519 pic18f66k80 family rrncf rotate right f (no carry) syntax: rrncf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) ? dest, (f<0>) ? dest<7> status affected: n, z encoding: 0100 00da ffff ffff description: the contents of register ?f? are rotated one bit to the right. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? is ? 1 ?, then the bank will be selected as per the bsr value. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1: rrncf reg, 1, 0 before instruction reg = 1101 0111 after instruction reg = 1110 1011 example 2: rrncf reg, 0, 0 before instruction w=? reg = 1101 0111 after instruction w = 1110 1011 reg = 1101 0111 register f setf set f syntax: setf f {,a} operands: 0 ? f ? 255 a ?? [0,1] operation: ffh ? f status affected: none encoding: 0110 100a ffff ffff description: the contents of the specified register are set to ffh. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: setf reg,1 before instruction reg = 5ah after instruction reg = ffh
pic18f66k80 family ds39977d-page 520 ? 2011 microchip technology inc. sleep enter sleep mode syntax: sleep operands: none operation: 00h ? wdt, 0 ? wdt postscaler, 1 ? to , 0 ? pd status affected: to , pd encoding: 0000 0000 0000 0011 description: the power-down status bit (pd ) is cleared. the time-out status bit (to ) is set. the watchdog timer and its postscaler are cleared. the processor is put into sleep mode with the oscillator stopped. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation process data go to sleep example: sleep before instruction to =? pd =? after instruction to = 1 ? pd = 0 ? if wdt causes wake-up, this bit is cleared. subfwb subtract f from w with borrow syntax: subfwb f {,d {,a}} operands: 0 ?? f ?? 255 d ? [0,1] a ? [0,1] operation: (w) ? (f) ? (c ) ?? dest status affected: n, ov, c, dc, z encoding: 0101 01da ffff ffff description: subtract register ?f? and carry flag (borrow) from w (2?s complement method). if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1: subfwb reg, 1, 0 before instruction reg = 3 w=2 c=1 after instruction reg = ff w=2 c=0 z=0 n = 1 ; result is negative example 2: subfwb reg, 0, 0 before instruction reg = 2 w=5 c=1 after instruction reg = 2 w=3 c=1 z=0 n = 0 ; result is positive example 3: subfwb reg, 1, 0 before instruction reg = 1 w=2 c=0 after instruction reg = 0 w=2 c=1 z = 1 ; result is zero n=0
? 2011 microchip technology inc. ds39977d-page 521 pic18f66k80 family sublw subtract w from literal syntax: sublw k operands: 0 ?? k ?? 255 operation: k ? (w) ?? w status affected: n, ov, c, dc, z encoding: 0000 1000 kkkk kkkk description: w is subtracted from the eight-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example 1: sublw 02h before instruction w = 01h c=? after instruction w = 01h c= 1 ; result is positive z= 0 n= 0 example 2: sublw 02h before instruction w = 02h c=? after instruction w = 00h c= 1 ; result is zero z= 1 n= 0 example 3: sublw 02h before instruction w = 03h c=? after instruction w = ffh ; (2?s complement) c= 0 ; result is negative z= 0 n= 1 subwf subtract w from f syntax: subwf f {,d {,a}} operands: 0 ?? f ?? 255 d ? [0,1] a ? [0,1] operation: (f) ? (w) ?? dest status affected: n, ov, c, dc, z encoding: 0101 11da ffff ffff description: subtract w from register ?f? (2?s complement method). if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1: subwf reg, 1, 0 before instruction reg = 3 w=2 c=? after instruction reg = 1 w=2 c = 1 ; result is positive z=0 n=0 example 2: subwf reg, 0, 0 before instruction reg = 2 w=2 c=? after instruction reg = 2 w=0 c = 1 ; result is zero z=1 n=0 example 3: subwf reg, 1, 0 before instruction reg = 1 w=2 c=? after instruction reg = ffh ;(2?s complement) w=2 c = 0 ; result is negative z=0 n=1
pic18f66k80 family ds39977d-page 522 ? 2011 microchip technology inc. subwfb subtract w from f with borrow syntax: subwfb f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f) ? (w) ? (c ) ?? dest status affected: n, ov, c, dc, z encoding: 0101 10da ffff ffff description: subtract w and the carry flag (borrow) from register ?f? (2?s complement method). if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1: subwfb reg, 1, 0 before instruction reg = 19h (0001 1001) w =0dh (0000 1101) c= 1 after instruction reg = 0ch (0000 1011) w =0dh (0000 1101) c= 1 z= 0 n= 0 ; result is positive example 2: subwfb reg, 0, 0 before instruction reg = 1bh (0001 1011) w =1ah (0001 1010) c= 0 after instruction reg = 1bh (0001 1011) w = 00h c= 1 z= 1 ; result is zero n= 0 example 3: subwfb reg, 1, 0 before instruction reg = 03h (0000 0011) w =0eh (0000 1101) c= 1 after instruction reg = f5h (1111 0100) ; [2?s comp] w =0eh (0000 1101) c= 0 z= 0 n= 1 ; result is negative swapf swap f syntax: swapf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (f<3:0>) ? dest<7:4>, (f<7:4>) ? dest<3:0> status affected: none encoding: 0011 10da ffff ffff description: the upper and lowe r nibbles of register ?f? are exchanged. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: swapf reg, 1, 0 before instruction reg = 53h after instruction reg = 35h
? 2011 microchip technology inc. ds39977d-page 523 pic18f66k80 family tblrd table read syntax: tblrd ( *; *+; *-; +*) operands: none operation: if tblrd *, (prog mem (tblptr)) ? tablat; tblptr ? no change if tblrd *+, (prog mem (tblptr)) ? tablat; (tblptr) + 1 ? tblptr if tblrd *-, (prog mem (tblptr)) ? tablat; (tblptr) ? 1 ? tblptr if tblrd +*, (tblptr) + 1 ? tblptr; (prog mem (tblptr)) ? tablat status affected: none encoding: 0000 0000 0000 10nn nn=0 * =1 *+ =2 *- =3 +* description: this instruction is used to read the contents of program memory (p.m.). to address the program memory, a pointer called table pointer (tblptr) is used. the tblptr (a 21-bit pointer) points to each byte in the program memory. tblptr has a 2-mbyte address range. tblptr<0> = 0 : least significant byte of program memory word tblptr<0> = 1 : most significant byte of program memory word the tblrd instruction can modify the value of tblptr as follows: ? no change ? post-increment ? post-decrement ? pre-increment words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation no operation no operation no operation no operation (read program memory) no operation no operation (write tablat) tblrd table read (continued) example 1: tblrd *+ ; before instruction tablat = 55h tblptr = 00a356h memory(00a356h) = 34h after instruction tablat = 34h tblptr = 00a357h example 2: tblrd +* ; before instruction tablat = aah tblptr = 01a357h memory(01a357h) = 12h memory(01a358h) = 34h after instruction tablat = 34h tblptr = 01a358h
pic18f66k80 family ds39977d-page 524 ? 2011 microchip technology inc. tblwt table write syntax: tblwt ( *; *+; *-; +*) operands: none operation: if tblwt*, (tablat) ? holding register; tblptr ? no change if tblwt*+, (tablat) ? holding register; (tblptr) + 1 ? tblptr if tblwt*-, (tablat) ? holding register; (tblptr) ? 1 ? tblptr if tblwt+*, (tblptr) + 1 ? tblptr; (tablat) ? holding register status affected: none encoding: 0000 0000 0000 11nn nn=0 * =1 *+ =2 *- =3 +* description: this instruction uses the 3 lsbs of tblptr to determine which of the 8 holding registers the tablat is written to. the holding registers are used to program the contents of program memory (p.m.). (refer to section 6.0 ?memory organization? for additional details on programming flash memory.) the tblptr (a 21-bit pointer) points to each byte in the program memory. tblptr has a 2-mbyte address range. the lsb of the tblptr selects which byte of the program memory location to access. tblptr[0] = 0 : least significant byte of program memory word tblptr[0] = 1 : most significant byte of program memory word the tblwt instruction can modify the value of tblptr as follows: ? no change ? post-increment ? post-decrement ? pre-increment words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation no operation no operation no operation no operation (read tablat) no operation no operation (write to holding register) tblwt table write (continued) example 1: tblwt *+; before instruction tablat = 55h tblptr = 00a356h holding register (00a356h) = ffh after instructions (table write completion) tablat = 55h tblptr = 00a357h holding register (00a356h) = 55h example 2: tblwt +*; before instruction tablat = 34h tblptr = 01389ah holding register (01389ah) = ffh holding register (01389bh) = ffh after instruction (table write completion) tablat = 34h tblptr = 01389bh holding register (01389ah) = ffh holding register (01389bh) = 34h
? 2011 microchip technology inc. ds39977d-page 525 pic18f66k80 family tstfsz test f, skip if 0 syntax: tstfsz f {,a} operands: 0 ? f ? 255 a ? [0,1] operation: skip if f = 0 status affected: none encoding: 0110 011a ffff ffff description: if ?f? = 0 , the next instruction fetched during the current instruction execution is discarded and a nop is executed, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here tstfsz cnt, 1 nzero : zero : before instruction pc = address (here) after instruction if cnt = 00h, pc = address (zero) if cnt ? 00h, pc = address (nzero) xorlw exclusive or literal with w syntax: xorlw k operands: 0 ?? k ?? 255 operation: (w) .xor. k ?? w status affected: n, z encoding: 0000 1010 kkkk kkkk description: the contents of w are xored with the 8-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: xorlw 0afh before instruction w=b5h after instruction w=1ah
pic18f66k80 family ds39977d-page 526 ? 2011 microchip technology inc. xorwf exclusive or w with f syntax: xorwf f {,d {,a}} operands: 0 ? f ? 255 d ? [0,1] a ? [0,1] operation: (w) .xor. (f) ?? dest status affected: n, z encoding: 0001 10da ffff ffff description: exclusive or the contents of w with register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in the register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank. if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f ?? 95 (5fh). see section 29.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: xorwf reg, 1, 0 before instruction reg = afh w=b5h after instruction reg = 1ah w=b5h
? 2011 microchip technology inc. ds39977d-page 527 pic18f66k80 family 29.2 extended instruction set in addition to the standard 75 instructions of the pic18 instruction set, the pic18f66k80 family of devices also provides an optional extension to the core cpu func- tionality. the added features include eight additional instructions that augment indirect and indexed addressing operations and the implementation of indexed literal offset addressing for many of the standard pic18 instructions. the additional features of the extended instruction set are enabled by default on unprogrammed devices. users must properly set or clear the xinst configura- tion bit during programming to enable or disable these features. the instructions in the extended set can all be classified as literal operations, which either manipulate the file select registers, or use them for indexed addressing. two of the instructions, addfsr and subfsr , each have an additional special instantiation for using fsr2. these versions ( addulnk and subulnk ) allow for automatic return after execution. the extended instructions are specifically implemented to optimize re-entrant program code (that is, code that is recursive or that uses a software stack) written in high-level languages, particularly c. among other things, they allow users working in high-level languages to perform certain operations on data structures more efficiently. these include: ? dynamic allocation and deallocation of software stack space when entering and leaving subroutines ? function pointer invocation ? software stack pointer manipulation ? manipulation of variables located in a software stack a summary of the instructions in the extended instruc- tion set is provided in tab l e 2 9- 3 . detailed descriptions are provided in section 29.2.2 ?extended instruction set? . the opcode field descriptions in tab l e 2 9- 1 (page 486) apply to both the standard and extended pic18 instruction sets. 29.2.1 extended instruction syntax most of the extended instructions use indexed argu- ments, using one of the file select registers and some offset to specify a source or destination register. when an argument for an instruction serves as part of indexed addressing, it is enclosed in square brackets (?[ ]?). this is done to indicate that the argument is used as an index or offset. the mpasm? assembler will flag an error if it determines that an index or offset value is not bracketed. when the extended instruction set is enabled, brackets are also used to indicate index arguments in byte-oriented and bit-oriented instructions. this is in addition to other changes in their syntax. for more details, see section 29.2.3.1 ?extended instruction syntax with standard pic18 commands? . table 29-3: extensions to the pic18 instruction set note: the instruction set extension and the indexed literal offset addressing mode were designed for optimizing applications written in c; the user may likely never use these instructions directly in assembler. the syntax for these commands is provided as a reference for users who may be reviewing code that has been generated by a compiler. note: in the past, square brackets have been used to denote optional arguments in the pic18 and earlier instruction sets. in this text and going forward, optional arguments are denoted by braces (?{ }?). mnemonic, operands description cycles 16-bit instruction word status affected msb lsb addfsr addulnk callw movsf movss pushl subfsr subulnk f, k k z s , f d z s , z d k f, k k add literal to fsr add literal to fsr2 and return call subroutine using wreg move z s (source) to 1st word f d (destination) 2nd word move z s (source) to 1st word z d (destination) 2nd word store literal at fsr2, decrement fsr2 subtract literal from fsr subtract literal from fsr2 and return 1 2 2 2 2 1 1 2 1110 1110 0000 1110 1111 1110 1111 1110 1110 1110 1000 1000 0000 1011 ffff 1011 xxxx 1010 1001 1001 ffkk 11kk 0001 0zzz ffff 1zzz xzzz kkkk ffkk 11kk kkkk kkkk 0100 zzzz ffff zzzz zzzz kkkk kkkk kkkk none none none none none none none none
pic18f66k80 family ds39977d-page 528 ? 2011 microchip technology inc. 29.2.2 extended instruction set addfsr add literal to fsr syntax: addfsr f, k operands: 0 ? k ? 63 f ? [ 0, 1, 2 ] operation: fsr(f) + k ? fsr(f) status affected: none encoding: 1110 1000 ffkk kkkk description: the 6-bit literal ?k? is added to the contents of the fsr specified by ?f?. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to fsr example: addfsr 2, 23h before instruction fsr2 = 03ffh after instruction fsr2 = 0422h addulnk add literal to fsr2 and return syntax: addulnk k operands: 0 ? k ? 63 operation: fsr2 + k ? fsr2, (tos) ?? pc status affected: none encoding: 1110 1000 11kk kkkk description: the 6-bit literal ?k? is added to the contents of fsr2. a return is then executed by loading the pc with the tos. the instruction takes two cycles to execute; a nop is performed during the second cycle. this may be thought of as a special case of the addfsr instruction, where f = 3 (binary ? 11 ?); it operates only on fsr2. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to fsr no operation no operation no operation no operation example: addulnk 23h before instruction fsr2 = 03ffh pc = 0100h after instruction fsr2 = 0422h pc = (tos) note: all pic18 instructions may take an optional label argument preceding the instruction mnemonic for use in symbolic addressing. if a label is used, the instruction format then becomes: {label} instruction argument(s).
? 2011 microchip technology inc. ds39977d-page 529 pic18f66k80 family callw subroutine call using wreg syntax: callw operands: none operation: (pc + 2) ? tos, (w) ? pcl, (pclath) ? pch, (pclatu) ? pcu status affected: none encoding: 0000 0000 0001 0100 description first, the return address (pc + 2) is pushed onto the return stack. next, the contents of w are written to pcl; the existing value is discarded. then, the contents of pclath and pclatu are latched into pch and pcu, respectively. the second cycle is executed as a nop instruction while the new next instruction is fetched. unlike call , there is no option to update w, status or bsr. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read wreg push pc to stack no operation no operation no operation no operation no operation example: here callw before instruction pc = address (here) pclath = 10h pclatu = 00h w = 06h after instruction pc = 001006h tos = address (here + 2) pclath = 10h pclatu = 00h w = 06h movsf move indexed to f syntax: movsf [z s ], f d operands: 0 ? z s ? 127 0 ? f d ? 4095 operation: ((fsr2) + z s ) ? f d status affected: none encoding: 1st word (source) 2nd word (destin.) 1110 1111 1011 ffff 0zzz ffff zzzz s ffff d description: the contents of the source register are moved to destination register ?f d ?. the actual address of the source register is determined by adding the 7-bit literal offset ?z s ?, in the first word, to the value of fsr2. the address of the destination register is specified by the 12-bit literal ?f d ? in the second word. both addresses can be anywhere in the 4096-byte data space (000h to fffh). the movsf instruction cannot use the pcl, tosu, tosh or tosl as the destination register. if the resultant source address points to an indirect addressing register, the value returned will be 00h. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode determine source addr determine source addr read source reg decode no operation no dummy read no operation write register ?f? (dest) example: movsf [05h], reg2 before instruction fsr2 = 80h contents of 85h = 33h reg2 = 11h after instruction fsr2 = 80h contents of 85h = 33h reg2 = 33h
pic18f66k80 family ds39977d-page 530 ? 2011 microchip technology inc. movss move indexed to indexed syntax: movss [z s ], [z d ] operands: 0 ? z s ? 127 0 ? z d ? 127 operation: ((fsr2) + z s ) ? ((fsr2) + z d ) status affected: none encoding: 1st word (source) 2nd word (dest.) 1110 1111 1011 xxxx 1zzz xzzz zzzz s zzzz d description the contents of the source register are moved to the destination register. the addresses of the source and destination registers are determined by adding the 7-bit literal offsets, ?z s ? or ?z d ?, respectively, to the value of fsr2. both registers can be located anywhere in the 4096-byte data memory space (000h to fffh). the movss instruction cannot use the pcl, tosu, tosh or tosl as the destination register. if the resultant source address points to an indirect addressing register, the value returned will be 00h. if the resultant destination address points to an indirect addressing register, the instruction will execute as a nop . words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode determine source addr determine source addr read source reg decode determine dest addr determine dest addr write to dest reg example: movss [05h], [06h] before instruction fsr2 = 80h contents of 85h = 33h contents of 86h = 11h after instruction fsr2 = 80h contents of 85h = 33h contents of 86h = 33h pushl store literal at fsr2, decrement fsr2 syntax: pushl k operands: 0 ??? k ? 255 operation: k ? (fsr2), fsr2 ? 1 ? fsr2 status affected: none encoding: 1111 1010 kkkk kkkk description: the 8-bit literal ?k? is written to the data memory address specified by fsr2. fsr2 is decremented by 1 after the operation. this instruction allows users to push values onto a software stack. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read ?k? process data write to destination example: pushl 08h before instruction fsr2h:fsr2l = 01ech memory (01ech) = 00h after instruction fsr2h:fsr2l = 01ebh memory (01ech) = 08h
? 2011 microchip technology inc. ds39977d-page 531 pic18f66k80 family subfsr subtract literal from fsr syntax: subfsr f, k operands: 0 ? k ? 63 f ? [ 0, 1, 2 ] operation: fsrf ? k ? fsrf status affected: none encoding: 1110 1001 ffkk kkkk description: the 6-bit literal ?k? is subtracted from the contents of the fsr specified by ?f?. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: subfsr 2, 23h before instruction fsr2 = 03ffh after instruction fsr2 = 03dch subulnk subtract literal from fsr2 and return syntax: subulnk k operands: 0 ? k ? 63 operation: fsr2 ? k ? fsr2, (tos) ?? pc status affected: none encoding: 1110 1001 11kk kkkk description: the 6-bit literal ?k? is subtracted from the contents of the fsr2. a return is then executed by loading the pc with the tos. the instruction takes two cycles to execute; a nop is performed during the second cycle. this may be thought of as a special case of the subfsr instruction, where f = 3 (binary ? 11 ?); it operates only on fsr2. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination no operation no operation no operation no operation example: subulnk 23h before instruction fsr2 = 03ffh pc = 0100h after instruction fsr2 = 03dch pc = (tos)
pic18f66k80 family ds39977d-page 532 ? 2011 microchip technology inc. 29.2.3 byte-oriented and bit-oriented instructions in indexed literal offset mode in addition to eight new commands in the extended set, enabling the extended instruction set also enables indexed literal offset addressing ( section 6.6.1 ?indexed addressing with literal offset? ). this has a significant impact on the way that many commands of the standard pic18 instruction set are interpreted. when the extended set is disabled, addresses embed- ded in opcodes are treated as literal memory locations: either as a location in the access bank (a = 0 ) or in a gpr bank designated by the bsr (a = 1 ). when the extended instruction set is enabled and a = 0 , however, a file register argument of 5fh or less is interpreted as an offset from the pointer value in fsr2 and not as a literal address. for practical purposes, this means that all instructions that use the access ram bit as an argument ? that is, all byte-oriented and bit-oriented instructions, or almost half of the core pic18 instruc- tions ? may behave differently when the extended instruction set is enabled. when the content of fsr2 is 00h, the boundaries of the access ram are essentially remapped to their original values. this may be useful in creating backward-compatible code. if this technique is used, it may be necessary to save the value of fsr2 and restore it when moving back and forth between c and assembly routines in order to preserve the stack pointer. users must also keep in mind the syntax requirements of the extended instruction set (see section 29.2.3.1 ?extended instruction syntax with standard pic18 commands? ). although the indexed literal offset mode can be very useful for dynamic stack and pointer manipulation, it can also be very annoying if a simple arithmetic opera- tion is carried out on the wrong register. users who are accustomed to the pic18 programming must keep in mind that, when the extended instruction set is enabled, register addresses of 5fh or less are used for indexed literal offset addressing. representative examples of typical byte-oriented and bit-oriented instructions in the indexed literal offset mode are provided on the following page to show how execution is affected. the operand conditions shown in the examples are applicable to all instructions of these types. 29.2.3.1 extended instruction syntax with standard pic18 commands when the extended instruction set is enabled, the file register argument ?f? in the standard byte-oriented and bit-oriented commands is replaced with the literal offset value ?k?. as already noted, this occurs only when ?f? is less than or equal to 5fh. when an offset value is used, it must be indicated by square brackets (?[ ]?). as with the extended instructions, the use of brackets indicates to the compiler that the value is to be interpreted as an index or an offset. omitting the brackets, or using a value greater than 5fh within the brackets, will generate an error in the mpasm? assembler. if the index argument is properly bracketed for indexed literal offset addressing, the access ram argument is never specified; it will automatically be assumed to be ? 0 ?. this is in contrast to standard operation (extended instruction set disabled), when ?a? is set on the basis of the target address. declaring the access ram bit in this mode will also generate an error in the mpasm assembler. the destination argument ?d? functions as before. in the latest versions of the mpasm assembler, language support for the extended instruction set must be explicitly invoked. this is done with either the command line option, /y , or the pe directive in the source listing. 29.2.4 considerations when enabling the extended instruction set it is important to note that the extensions to the instruc- tion set may not be beneficial to all users. in particular, users who are not writing code that uses a software stack may not benefit from using the extensions to the instruction set. additionally, the indexed literal offset addressing mode may create issues with legacy applications written to the pic18 assembler. this is because instructions in the legacy code may attempt to address registers in the access bank below 5fh. since these addresses are interpreted as literal offsets to fsr2 when the instruction set extension is enabled, the application may read or write to the wrong data addresses. when porting an application to the pic18f66k80 family, it is very important to consider the type of code. a large, re-entrant application that is written in c and would benefit from efficient compilation will do well when using the instruction set extensions. legacy applications that heavily use the access bank will most likely not benefit from using the extended instruction set. note: enabling the pic18 instruction set exten- sion may cause legacy applications to behave erratically or fail entirely.
? 2011 microchip technology inc. ds39977d-page 533 pic18f66k80 family addwf add w to indexed (indexed literal offset mode) syntax: addwf [k] {,d} operands: 0 ? k ? 95 d ? [0,1] operation: (w) + ((fsr2) + k) ? dest status affected: n, ov, c, dc, z encoding: 0010 01d0 kkkk kkkk description: the contents of w are added to the contents of the register indicated by fsr2, offset by the value ?k?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read ?k? process data write to destination example: addwf [ofst] ,0 before instruction w = 17h ofst = 2ch fsr2 = 0a00h contents of 0a2ch = 20h after instruction w = 37h contents of 0a2ch = 20h bsf bit set indexed (indexed literal offset mode) syntax: bsf [k], b operands: 0 ? f ? 95 0 ? b ? 7 operation: 1 ? ((fsr2) + k) status affected: none encoding: 1000 bbb0 kkkk kkkk description: bit ?b? of the register indicated by fsr2, offset by the value ?k?, is set. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: bsf [flag_ofst], 7 before instruction flag_ofst = 0ah fsr2 = 0a00h contents of 0a0ah = 55h after instruction contents of 0a0ah = d5h setf set indexed (indexed literal offset mode) syntax: setf [k] operands: 0 ? k ? 95 operation: ffh ? ((fsr2) + k) status affected: none encoding: 0110 1000 kkkk kkkk description: the contents of the register indicated by fsr2, offset by ?k?, are set to ffh. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read ?k? process data write register example: setf [ofst] before instruction ofst = 2ch fsr2 = 0a00h contents of 0a2ch = 00h after instruction contents of 0a2ch = ffh
pic18f66k80 family ds39977d-page 534 ? 2011 microchip technology inc. 29.2.5 special considerations with microchip mplab ? ide tools the latest versions of microchip?s software tools have been designed to fully support the extended instruction set for the pic18f66k80 family. this includes the mplab c18 c compiler, mpasm assembly language and mplab integrated development environment (ide). when selecting a target device for software development, mplab ide will automatically set default configuration bits for that device. the default setting for the xinst configuration bit is ? 0 ?, disabling the extended instruction set and indexed literal offset addressing. for proper execution of applications developed to take advantage of the extended instruction set, xinst must be set during programming. to develop software for the extended instruction set, the user must enable support for the instructions and the indexed addressing mode in their language tool(s). depending on the environment being used, this may be done in several ways: ? a menu option or dialog box within the environment that allows the user to configure the language tool and its settings for the project ? a command line option ? a directive in the source code these options vary between different compilers, assemblers and development environments. users are encouraged to review the documentation accompany- ing their development systems for the appropriate information.
? 2011 microchip technology inc. ds39977d-page 535 pic18f66k80 family 30.0 development support the pic ? microcontrollers and dspic ? digital signal controllers are supported with a full range of software and hardware development tools: ? integrated development environment - mplab ? ide software ? compilers/assemblers/linkers - mplab c compiler for various device families - hi-tech c for various device families - mpasm tm assembler -mplink tm object linker/ mplib tm object librarian - mplab assembler/linker/librarian for various device families ? simulators - mplab sim software simulator ?emulators - mplab real ice? in-circuit emulator ? in-circuit debuggers - mplab icd 3 - pickit? 3 debug express ? device programmers - pickit? 2 programmer - mplab pm3 device programmer ? low-cost demonstration/development boards, evaluation kits, and starter kits 30.1 mplab integrated development environment software the mplab ide software brings an ease of software development previously unseen in the 8/16/32-bit microcontroller market. the mplab ide is a windows ? operating system-based application that contains: ? a single graphical interface to all debugging tools - simulator - programmer (sold separately) - in-circuit emulator (sold separately) - in-circuit debugger (sold separately) ? a full-featured editor with color-coded context ? a multiple project manager ? customizable data windows with direct edit of contents ? high-level source code debugging ? mouse over variable inspection ? drag and drop variables from source to watch windows ? extensive on-line help ? integration of select third party tools, such as iar c compilers the mplab ide allows you to: ? edit your source files (either c or assembly) ? one-touch compile or assemble, and download to emulator and simulator tools (automatically updates all project information) ? debug using: - source files (c or assembly) - mixed c and assembly - machine code mplab ide supports multiple debugging tools in a single development paradigm, from the cost-effective simulators, through low-cost in-circuit debuggers, to full-featured emulators. this eliminates the learning curve when upgrading to tools with increased flexibility and power.
pic18f66k80 family ds39977d-page 536 ? 2011 microchip technology inc. 30.2 mplab c compilers for various device families the mplab c compiler code development systems are complete ansi c compilers for microchip?s pic18, pic24 and pic32 families of microcontrollers and the dspic30 and dspic33 families of digital signal control- lers. these compilers provide powerful integration capabilities, superior code optimization and ease of use. for easy source level debugging, the compilers provide symbol information that is optimized to the mplab ide debugger. 30.3 hi-tech c for various device families the hi-tech c compiler code development systems are complete ansi c compilers for microchip?s pic family of microcontrollers and the dspic family of digital signal controllers. these compilers provide powerful integration capabilities, omniscient code generation and ease of use. for easy source level debugging, the compilers provide symbol information that is optimized to the mplab ide debugger. the compilers include a macro assembler, linker, pre- processor, and one-step driver, and can run on multiple platforms. 30.4 mpasm assembler the mpasm assembler is a full-featured, universal macro assembler for pic10/12/16/18 mcus. the mpasm assembler generates relocatable object files for the mplink object linker, intel ? standard hex files, map files to detail memory usage and symbol reference, absolute lst files that contain source lines and generated machine code and coff files for debugging. the mpasm assembler features include: ? integration into mplab ide projects ? user-defined macros to streamline assembly code ? conditional assembly for multi-purpose source files ? directives that allow complete control over the assembly process 30.5 mplink object linker/ mplib object librarian the mplink object linker combines relocatable objects created by the mpasm assembler and the mplab c18 c compiler. it can link relocatable objects from precompiled libraries, using directives from a linker script. the mplib object librarian manages the creation and modification of library files of precompiled code. when a routine from a library is called from a source file, only the modules that contain that routine will be linked in with the application. this allows large libraries to be used efficiently in many different applications. the object linker/library features include: ? efficient linking of single libraries instead of many smaller files ? enhanced code maintainability by grouping related modules together ? flexible creation of libraries with easy module listing, replacement, deletion and extraction 30.6 mplab assembler, linker and librarian for various device families mplab assembler produces relocatable machine code from symbolic assembly language for pic24, pic32 and dspic devices. mplab c compiler uses the assembler to produce its object file. the assembler generates relocatable object files that can then be archived or linked with other relocatable object files and archives to create an executable file. notable features of the assembler include: ? support for the entire device instruction set ? support for fixed-point and floating-point data ? command line interface ? rich directive set ? flexible macro language ? mplab ide compatibility
? 2011 microchip technology inc. ds39977d-page 537 pic18f66k80 family 30.7 mplab sim software simulator the mplab sim software simulator allows code development in a pc-hosted environment by simulat- ing the pic mcus and dspic ? dscs on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a comprehensive stimulus controller. registers can be logged to files for further run-time analysis. the trace buffer and logic analyzer display extend the power of the simulator to record and track program execution, actions on i/o, most peripherals and internal registers. the mplab sim software simulator fully supports symbolic debugging using the mplab c compilers, and the mpasm and mplab assemblers. the soft- ware simulator offers the flexibility to develop and debug code outside of the hardware laboratory envi- ronment, making it an excellent, economical software development tool. 30.8 mplab real ice in-circuit emulator system mplab real ice in-circuit emulator system is microchip?s next generation high-speed emulator for microchip flash dsc and mcu devices. it debugs and programs pic ? flash mcus and dspic ? flash dscs with the easy-to-use, powerful graphical user interface of the mplab integrated development environment (ide), included with each kit. the emulator is connected to the design engineer?s pc using a high-speed usb 2.0 interface and is connected to the target with either a connector compatible with in- circuit debugger systems (rj11) or with the new high- speed, noise tolerant, low-voltage differential signal (lvds) interconnection (cat5). the emulator is field upgradable through future firmware downloads in mplab ide. in upcoming releases of mplab ide, new devices will be supported, and new features will be added. mplab real ice offers significant advantages over competitive emulators including low-cost, full-speed emulation, run-time variable watches, trace analysis, complex breakpoints, a ruggedized probe interface and long (up to three meters) interconnection cables. 30.9 mplab icd 3 in-circuit debugger system mplab icd 3 in-circuit debugger system is micro- chip's most cost effective high-speed hardware debugger/programmer for microchip flash digital sig- nal controller (dsc) and microcontroller (mcu) devices. it debugs and programs pic ? flash microcon- trollers and dspic ? dscs with the powerful, yet easy- to-use graphical user interface of mplab integrated development environment (ide). the mplab icd 3 in-circuit debugger probe is con- nected to the design engineer's pc using a high-speed usb 2.0 interface and is connected to the target with a connector compatible with the mplab icd 2 or mplab real ice systems (rj-11). mplab icd 3 supports all mplab icd 2 headers. 30.10 pickit 3 in-circuit debugger/ programmer and pickit 3 debug express the mplab pickit 3 allows debugging and program- ming of pic ? and dspic ? flash microcontrollers at a most affordable price point using the powerful graphical user interface of the mplab integrated development environment (ide). the mplab pickit 3 is connected to the design engineer's pc using a full speed usb interface and can be connected to the target via an microchip debug (rj-11) connector (compatible with mplab icd 3 and mplab real ice). the connector uses two device i/o pins and the reset line to imple- ment in-circuit debugging and in-circuit serial pro- gramming?. the pickit 3 debug express include the pickit 3, demo board and microcontroller, hookup cables and cdrom with user?s guide, lessons, tutorial, compiler and mplab ide software.
pic18f66k80 family ds39977d-page 538 ? 2011 microchip technology inc. 30.11 pickit 2 development programmer/debugger and pickit 2 debug express the pickit? 2 development programmer/debugger is a low-cost development tool with an easy to use inter- face for programming and debugging microchip?s flash families of microcontrollers. the full featured windows ? programming interface supports baseline (pic10f, pic12f5xx, pic16f5xx), midrange (pic12f6xx, pic16f), pic18f, pic24, dspic30, dspic33, and pic32 families of 8-bit, 16-bit, and 32-bit microcontrollers, and many microchip serial eeprom products. with microchip?s powerful mplab integrated development environment (ide) the pickit? 2 enables in-circuit debugging on most pic ? microcon- trollers. in-circuit-debugging runs, halts and single steps the program while the pic microcontroller is embedded in the application. when halted at a break- point, the file registers can be examined and modified. the pickit 2 debug express include the pickit 2, demo board and microcontroller, hookup cables and cdrom with user?s guide, lessons, tutorial, compiler and mplab ide software. 30.12 mplab pm3 device programmer the mplab pm3 device programmer is a universal, ce compliant device programmer with programmable voltage verification at v ddmin and v ddmax for maximum reliability. it features a large lcd display (128 x 64) for menus and error messages and a modu- lar, detachable socket assembly to support various package types. the icsp? cable assembly is included as a standard item. in stand-alone mode, the mplab pm3 device programmer can read, verify and program pic devices without a pc connection. it can also set code protection in this mode. the mplab pm3 connects to the host pc via an rs-232 or usb cable. the mplab pm3 has high-speed communications and optimized algorithms for quick programming of large memory devices and incorporates an mmc card for file storage and data applications. 30.13 demonstration/development boards, evaluation kits, and starter kits a wide variety of demonstration, development and evaluation boards for various pic mcus and dspic dscs allows quick application development on fully func- tional systems. most boards include prototyping areas for adding custom circuitry and provide application firmware and source code for examination and modification. the boards support a variety of features, including leds, temperature sensors, switches, speakers, rs-232 interfaces, lcd displays, potentiometers and additional eeprom memory. the demonstration and development boards can be used in teaching environments, for prototyping custom circuits and for learning about various microcontroller applications. in addition to the picdem? and dspicdem? demon- stration/development board series of circuits, microchip has a line of evaluation kits and demonstration software for analog filter design, k ee l oq ? security ics, can, irda ? , powersmart battery management, seeval ? evaluation system, sigma-delta adc, flow rate sensing, plus many more. also available are starter kits that contain everything needed to experience the specified device. this usually includes a single application and debug capability, all on one board. check the microchip web page ( www.microchip.com ) for the complete list of demonstration, development and evaluation kits.
? 2011 microchip technology inc. ds39977d-page 539 pic18f66k80 family 31.0 electrical characteristics absolute maximum ratings (?) ambient temperature under bias................................................................................................. ............-40c to +125c storage temperature ............................................................................................................ .................. -65c to +150c voltage on mclr with respect to v ss .......................................................................................................... -0.3v to 9.0v voltage on any digital only i/o pin with respect to v ss (except v dd )........................................................... -0.3v to 7.5v voltage on any combined digital and analog pin with respect to v ss (except v dd and mclr )...... -0.3v to (v dd + 0.3v) voltage on v dd with respect to v ss (pic18f66k80) .................................................................................. -0.3v to 7.5v voltage on v dd with respect to v ss (pic18lf66k80) .............................................................................. -0.3v to 3.66v total power dissipation (note 1) ............................................................................................................................... ...1w maximum current out of v ss pin ........................................................................................................................... 300 ma maximum current into v dd pin ........................................................................................................................... ...250 ma input clamp current, i ik (v i < 0 or v i > v dd ) ......................................................................................................... 20 ma output clamp current, i ok (v o < 0 or v o > v dd ) .................................................................................................. 20 ma maximum output current sunk by porta<7:6> and any portb and portc i/o pins.........................................25 ma maximum output current sunk by any portd and porte i/o pins.................................................................... ....8 ma maximum output current sunk by porta<5:0> and any portf and portg i/o pins...........................................2 ma maximum output current sourced by porta<7:6> and any portb and portc i/o pins ...................................25 ma maximum output current sourced by any portd, porte and portj i/o pins .....................................................8 ma maximum output current sourced by porta<5:0> and any portf, portg and porth i/o pins .......................2 ma maximum current sunk by ? all ports combined.......................................................................................................200 ma note 1: power dissipation is calculated as follows: pdis = v dd x {i dd ? ? i oh } + ? {(v dd ? v oh ) x i oh } + ? (v ol x i ol ) ? notice: stresses above those listed under ?absolute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the device at those or any other conditions above those indicated in the operation listings of this specification is not implied. exposure to maximum rating conditions for extended periods may affect device reliability.
pic18f66k80 family ds39977d-page 540 ? 2011 microchip technology inc. figure 31-1: voltage-frequency graph, regulator enabled (industrial/extended) (1) figure 31-2: voltage-frequency graph, regulator disabled (industrial/extended) (1,2) frequency voltage (v dd ) 6v 1.8v 64 mhz 5v 4v 3v 5.5v 3v 0 4 mhz pic18f66k80 family note 1: for v dd values 1.8v to 3v, f max = (v dd ? 1.72)/0.02 mhz. frequency voltage (v dd ) 4v 1.8v 64 mhz 3.75v 3.25v 2.5v 3.6v 4 mhz 3v note 1: when the on-chip voltage regulator is disabled, v dd must be maintained so that v dd ?? 3.6v. 2: for v dd values 1.8v to 3v, f max = (v dd ? 1.72)/0.02 mhz. pic18lf66k80 family
? 2011 microchip technology inc. ds39977d-page 541 pic18f66k80 family 31.1 dc characteristics: supply voltage pic18f66k80 family (industrial/extended) pic18f66k80 family (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. symbol characteristic min typ max units conditions d001 v dd supply voltage 1.8 1.8 ? ? 3.6 5.5 v v for lf devices for f devices d001c av dd analog supply voltage v dd ? 0.3 ? v dd + 0.3 v d001d av ss analog ground potential v ss ? 0.3 ? v ss + 0.3 v d002 v dr ram data retention voltage (1) 1.5 ? ? v d003 v por v dd start voltage to ensure internal power-on reset signal ??0.7vsee section 5.3 ?power-on reset (por)? for details d004 s vdd v dd rise rate to ensure internal power-on reset signal 0.05 ? ? v/ms see section 5.3 ?power-on reset (por)? for details d005 b vdd brown-out reset voltage (high, medium and low-power mode borv<1:0> = 11 (2) borv<1:0> = 10 borv<1:0> = 01 borv<1:0> = 00 1.69 1.88 2.53 2.82 1.8 2.0 2.7 3.0 1.91 2.12 2.86 3.18 v v v v note 1: this is the limit to which v dd can be lowered in sleep mode, or during a device reset, without losing ram data. 2: device will operate normally until brown-out reset occurs, even though v dd may be below v ddmin .
pic18f66k80 family ds39977d-page 542 ? 2011 microchip technology inc. 31.2 dc characteristics: power-down and supply current pic18f66k80 family (industrial/extended) pic18f66k80 family (industrial/extended) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. device typ max units conditions power-down current (i pd ) (1) pic18 lf xxk80 8 400 na -40c v dd = 1.8v ( sleep mode) regulator disabled 13 500 na +25c 35 750 na +60c 218 980 na +85c 36 ? a +125c pic18 lf xxk80 14 500 na -40c v dd = 3.3v ( sleep mode) regulator disabled 34 600 na +25c 92 850 na +60c 312 1250 na +85c 4 8 a +125c pic18 f xxk80 200 700 na -40c v dd = 3.3v ( sleep mode) regulator enabled 230 800 na +25c 320 1050 na +60c 510 1500 na +85c 5 9 a +125c pic18 f xxk80 220 1000 na -40c v dd = 5v ( sleep mode) regulator enabled 240 1000 na +25c 340 1100 na +60c 540 1580 na +85c 5 10 a +125c legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss , and all features that add delta current disabled (such as wdt, sosc oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: for lf devices, reten (config1l<0>) = 1 . 5: for f devices, sreten (wdtcon<4>) = 1 and reten (config1l<0>) = 0 .
? 2011 microchip technology inc. ds39977d-page 543 pic18f66k80 family supply current (i dd ) (2,3) pic18 lf xxk80 4 8 ? a -40c v dd = 1.8v (4) regulator disabled f osc = 31 khz ( rc_run mode, lf-intosc) 48 ? a +25c 48 ? a +60c 59 ? a +85c 912 ? a +125c pic18 lf xxk80 7 11 ? a -40c v dd = 3.3v (4) regulator disabled 711 ? a +25c 711 ? a +60c 812 ? a +85c 13 15 ? a +125c pic18 f xxk80 51 150 ? a -40c v dd = 3.3v (5) regulator enabled 70 150 ? a +25c 75 150 ? a +60c 80 170 ? a +85c 88 190 ? a +125c pic18 f xxk80 75 180 ? a -40c v dd = 5v (5) regulator enabled 75 180 ? a +25c 75 180 ? a +60c 80 190 ? a +85c 95 200 ? a +125c 31.2 dc characteristics: power-down and supply current pic18f66k80 family (industrial/extended) (continued) pic18f66k80 family (industrial/extended) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss , and all features that add delta current disabled (such as wdt, sosc oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-r ail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: for lf devices, reten (config1l<0>) = 1 . 5: for f devices, sreten (wdtcon<4>) = 1 and reten (config1l<0>) = 0 .
pic18f66k80 family ds39977d-page 544 ? 2011 microchip technology inc. supply current (i dd ) cont. (2,3) pic18 lf xxk80 274 600 ? a -40c v dd = 1.8v (4) regulator disabled f osc = 1 mhz ( rc_run mode, hf-intosc) 274 600 ? a +25c 274 600 ? a +60c 280 650 ? a +85c 290 700 ? a +125c pic18 lf xxk80 410 820 ? a -40c v dd = 3.3v (4) regulator disabled 410 820 ? a +25c 410 820 ? a +60c 420 840 ? a +85c 430 990 ? a +125c pic18 f xxk80 490 860 ? a -40c v dd = 3.3v (5) regulator enabled 490 860 ? a +25c 490 860 ? a +60c 500 890 ? a +85c 510 1060 ? a +125c pic18 f xxk80 490 910 ? a -40c v dd = 5v (5) regulator enabled 490 910 ? a +25c 490 910 ? a +60c 500 970 ? a +85c 510 1125 ? a +125c 31.2 dc characteristics: power-down and supply current pic18f66k80 family (industrial/extended) (continued) pic18f66k80 family (industrial/extended) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss , and all features that add delta current disabled (such as wdt, sosc oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: for lf devices, reten (config1l<0>) = 1 . 5: for f devices, sreten (wdtcon<4>) = 1 and reten (config1l<0>) = 0 .
? 2011 microchip technology inc. ds39977d-page 545 pic18f66k80 family supply current (i dd ) cont. (2,3) pic18 lf xxk80 520 820 a -40c v dd = 1.8v (4) regulator disabled f osc = 4 mhz ( rc_run mode, hf-intosc) 520 820 a +25c 520 820 a +60c 530 880 a +85c 540 1000 a +125c pic18 lf xxk80 941 1600 a -40c v dd = 3.3v (4) regulator disabled 941 1600 a +25c 941 1600 a +60c 950 1610 a +85c 960 1800 a +125c pic18 f xxk80 981 1640 ? a -40c v dd = 3.3v (5) regulator enabled 981 1640 ? a +25c 981 1640 ? a +60c 990 1650 ? a +85c 1000 1900 ? a +125c pic18 f xxk80 1 2.2 ma -40c v dd = 5v (5) regulator enabled 1 2.2 ma +25c 1 2.2 ma +60c 1 2.2 ma +85c 1 2.2 ma +125c 31.2 dc characteristics: power-down and supply current pic18f66k80 family (industrial/extended) (continued) pic18f66k80 family (industrial/extended) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss , and all features that add delta current disabled (such as wdt, sosc oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-r ail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: for lf devices, reten (config1l<0>) = 1 . 5: for f devices, sreten (wdtcon<4>) = 1 and reten (config1l<0>) = 0 .
pic18f66k80 family ds39977d-page 546 ? 2011 microchip technology inc. supply current (i dd ) cont. (2,3) pic18 lf xxk80 880 1600 na -40c v dd = 1.8v (4) regulator disabled f osc = 31 khz ( rc_idle mode, lf-intosc) 880 1600 na +25c 880 1600 na +60c 12 ? a +85c 510 ? a +125c pic18 lf xxk80 1.6 5 ? a -40c v dd = 3.3v (4) regulator disabled 1.6 5 ? a +25c 1.6 5 ? a +60c 26 ? a +85c 712 ? a +125c pic18 f xxk80 41 130 ? a -40c v dd = 3.3v (5) regulator enabled 59 130 ? a +25c 64 130 ? a +60c 70 150 ? a +85c 80 175 ? a +125c pic18 f xxk80 53 160 ? a -40c v dd = 5v (5) regulator enabled 62 160 ? a +25c 70 160 ? a +60c 85 170 ? a +85c 100 180 ? a +125c 31.2 dc characteristics: power-down and supply current pic18f66k80 family (industrial/extended) (continued) pic18f66k80 family (industrial/extended) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss , and all features that add delta current disabled (such as wdt, sosc oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: for lf devices, reten (config1l<0>) = 1 . 5: for f devices, sreten (wdtcon<4>) = 1 and reten (config1l<0>) = 0 .
? 2011 microchip technology inc. ds39977d-page 547 pic18f66k80 family supply current (i dd ) cont. (2,3) pic18 lf xxk80 260 380 ? a -40c v dd = 1.8v (4) regulator disabled f osc = 1 mhz ( rc_idle mode, hf-intosc) 260 380 ? a +25c 260 380 ? a +60c 270 390 ? a +85c 280 420 ? a +125c pic18 lf xxk80 400 500 ? a -40c v dd = 3.3v (4) regulator disabled 400 500 ? a +25c 400 500 ? a +60c 410 520 ? a +85c 420 580 ? a +125c pic18 f xxk80 430 560 ? a -40c v dd = 3.3v (5) regulator enabled 430 560 ? a +25c 430 560 ? a +60c 450 580 ? a +85c 480 620 ? a +125c pic18 f xxk80 450 620 ? a -40c v dd = 5v (5) regulator enabled 450 620 ? a +25c 450 620 ? a +60c 470 640 ? a +85c 500 680 ? a +125c 31.2 dc characteristics: power-down and supply current pic18f66k80 family (industrial/extended) (continued) pic18f66k80 family (industrial/extended) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss , and all features that add delta current disabled (such as wdt, sosc oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-r ail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: for lf devices, reten (config1l<0>) = 1 . 5: for f devices, sreten (wdtcon<4>) = 1 and reten (config1l<0>) = 0 .
pic18f66k80 family ds39977d-page 548 ? 2011 microchip technology inc. supply current (i dd ) cont. (2,3) pic18 lf xxk80 330 480 ? a -40c v dd = 1.8v (4) regulator disabled f osc = 4 mhz ( rc_idle mode, internal hf-intosc) 330 480 ? a +25c 330 480 ? a +60c 340 500 ? a +85c 350 540 ? a +125c pic18 lf xxk80 522 720 ? a -40c v dd = 3.3v (4) regulator disabled 522 720 ? a +25c 522 720 ? a +60c 540 740 ? a +85c 550 780 ? a +125c pic18 f xxk80 540 760 ? a -40c v dd = 3.3v (5) regulator enabled 540 760 ? a +25c 540 760 ? a +60c 560 780 ? a +85c 580 810 ? a +125c pic18 f xxk80 600 1250 ? a -40c v dd = 5v (5) regulator enabled 600 1250 ? a +25c 600 1250 ? a +60c 610 1300 ? a +85c 620 1340 ? a +125c 31.2 dc characteristics: power-down and supply current pic18f66k80 family (industrial/extended) (continued) pic18f66k80 family (industrial/extended) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss , and all features that add delta current disabled (such as wdt, sosc oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: for lf devices, reten (config1l<0>) = 1 . 5: for f devices, sreten (wdtcon<4>) = 1 and reten (config1l<0>) = 0 .
? 2011 microchip technology inc. ds39977d-page 549 pic18f66k80 family supply current (i dd ) cont. (2,3) pic18 lf xxk80 90 260 ? a -40c v dd = 1.8v (4) regulator disabled f osc = 1 mh z ( pri_run mode, ec oscillator) 90 260 ? a +25c 90 260 ? a +60c 100 270 ? a +85c 110 300 ? a +125c pic18 lf xxk80 163 540 ? a -40c v dd = 3.3v (4) regulator disabled 163 540 ? a +25c 163 540 ? a +60c 170 560 ? a +85c 180 600 ? a +125c pic18 f xxk80 201 560 ? a -40c v dd = 3.3v (5) regulator enabled 217 560 ? a +25c 224 560 ? a +60c 228 580 ? a +85c 236 620 ? a +125c pic18 f xxk80 240 740 ? a -40c v dd = 5v (5) regulator enabled 240 740 ? a +25c 240 740 ? a +60c 250 840 ? a +85c 260 940 ? a +125c 31.2 dc characteristics: power-down and supply current pic18f66k80 family (industrial/extended) (continued) pic18f66k80 family (industrial/extended) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss , and all features that add delta current disabled (such as wdt, sosc oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-r ail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: for lf devices, reten (config1l<0>) = 1 . 5: for f devices, sreten (wdtcon<4>) = 1 and reten (config1l<0>) = 0 .
pic18f66k80 family ds39977d-page 550 ? 2011 microchip technology inc. supply current (i dd ) cont. (2,3) pic18 lf xxk80 270 600 ? a -40c v dd = 1.8v (4) regulator disabled f osc = 4 mhz ( pri_run mode, ec oscillator) 270 600 ? a +25c 270 600 ? a +60c 300 700 ? a +85c 320 850 ? a +125c pic18 lf xxk80 540 1000 ? a -40c v dd = 3.3v (4) regulator disabled 540 1000 ? a +25c 540 1000 ? a +60c 550 1100 ? a +85c 560 1200 ? a +125c pic18 f xxk80 566 1020 ? a -40c v dd = 3.3v (5) regulator enabled 585 1020 ? a +25c 590 1020 ? a +60c 595 1120 ? a +85c 600 1220 ? a +125c pic18 f xxk80 630 2000 ? a -40c v dd = 5v (5) regulator enabled 630 2000 ? a +25c 630 2000 ? a +60c 640 2000 ? a +85c 650 2000 ? a +125c 31.2 dc characteristics: power-down and supply current pic18f66k80 family (industrial/extended) (continued) pic18f66k80 family (industrial/extended) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss , and all features that add delta current disabled (such as wdt, sosc oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: for lf devices, reten (config1l<0>) = 1 . 5: for f devices, sreten (wdtcon<4>) = 1 and reten (config1l<0>) = 0 .
? 2011 microchip technology inc. ds39977d-page 551 pic18f66k80 family supply current (i dd ) cont. (2,3) pic18 lf xxk80 7 11 ma -40c v dd = 3.3v (4) regulator disabled f osc = 64 mh z ( pri_run mode, ec oscillator) 7 11 ma +25c 7 11 ma +60c 7 11 ma +85c 7 11 ma +125c pic18 f xxk80 7 11 ma -40c v dd = 3.3v (5) regulator enabled 7 11 ma +60c 7 11 ma +25c 7 11 ma +85c 7 11 ma +125c pic18 f xxk80 8 12 ma -40c v dd = 5v (5) regulator enabled 8 12 ma +60c 8 12 ma +25c 8 12 ma +85c 8 12 ma +125c 31.2 dc characteristics: power-down and supply current pic18f66k80 family (industrial/extended) (continued) pic18f66k80 family (industrial/extended) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss , and all features that add delta current disabled (such as wdt, sosc oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-r ail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: for lf devices, reten (config1l<0>) = 1 . 5: for f devices, sreten (wdtcon<4>) = 1 and reten (config1l<0>) = 0 .
pic18f66k80 family ds39977d-page 552 ? 2011 microchip technology inc. supply current (i dd ) cont. (2,3) pic18 lf xxk80 2 5 ma -40c v dd = 3.3v (4) f osc = 16 mhz ( pri_run mode, 4 mhz ec oscillator with pll) 2 5 ma +25c 2 5 ma +60c 2 5 ma +85c 2 5 ma +125c pic18 f xxk80 2 5 ma -40c v dd = 3.3v (5) regulator enabled 2 5 ma +25c 2 5 ma +60c 2 5 ma +85c 2 5 ma +125c pic18 f xxk80 2.2 6 ma -40c v dd = 5v (5) regulator enabled 2.2 6 ma +25c 2.2 6 ma +60c 2.2 6 ma +85c 2.2 6 ma +125c pic18 lf xxk80 7 11 ma -40c v dd = 3.3v (4) f osc = 64 mhz ( pri_run mode, 16 mhz ec oscillator with pll) 7 11 ma +25c 7 11 ma +60c 7 11 ma +85c 7 11 ma +125c pic18 f xxk80 7 11 ma -40c v dd = 3.3v (5) regulator enabled 7 11 ma +25c 7 11 ma +60c 7 11 ma +85c 7 11 ma +125c pic18 f xxk80 8 12 ma -40c v dd = 5v (5) regulator enabled 8 12 ma +25c 8 12 ma +60c 8 12 ma +85c 8 12 ma +125c 31.2 dc characteristics: power-down and supply current pic18f66k80 family (industrial/extended) (continued) pic18f66k80 family (industrial/extended) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss , and all features that add delta current disabled (such as wdt, sosc oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: for lf devices, reten (config1l<0>) = 1 . 5: for f devices, sreten (wdtcon<4>) = 1 and reten (config1l<0>) = 0 .
? 2011 microchip technology inc. ds39977d-page 553 pic18f66k80 family supply current (i dd ) cont. (2,3) pic18 lf xxk80 20 70 a -40c v dd = 1.8v (4) regulator disabled f osc = 1 mhz ( pri_idle mode, ec oscillator) 20 70 a +25c 20 70 a +60c 25 80 a +85c 30 100 a +125c pic18 lf xxk80 37 120 a -40c v dd = 3.3v (4) regulator disabled 37 120 a +25c 37 120 a +60c 40 130 a +85c 45 150 a +125c pic18 f xxk80 85 140 a -40c v dd = 3.3v (5) regulator enabled 100 140 a +25c 105 140 a +60c 110 150 a +85c 120 170 a +125c pic18 f xxk80 110 225 a -40c v dd = 5v (5) regulator enabled 110 225 a +25c 110 225 a +60c 120 230 a +85c 130 250 a +125c 31.2 dc characteristics: power-down and supply current pic18f66k80 family (industrial/extended) (continued) pic18f66k80 family (industrial/extended) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss , and all features that add delta current disabled (such as wdt, sosc oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-r ail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: for lf devices, reten (config1l<0>) = 1 . 5: for f devices, sreten (wdtcon<4>) = 1 and reten (config1l<0>) = 0 .
pic18f66k80 family ds39977d-page 554 ? 2011 microchip technology inc. supply current (i dd ) cont. (2,3) pic18 lf xxk80 75 160 a -40c v dd = 1.8v (4) regulator disabled f osc = 4 mhz ( pri_idle mode, ec oscillator) 75 160 a +25c 75 160 a +60c 76 170 a +85c 82 180 a +125c pic18 lf xxk80 148 300 a -40c v dd = 3.3v (4) regulator disabled 148 300 a +25c 148 300 a +60c 150 400 a +85c 157 460 a +125c pic18 f xxk80 187 320 a -40c v dd = 3.3v (5) regulator enabled 204 320 a +25c 212 320 a +60c 218 420 a +85c 230 480 a +125c pic18 f xxk80 230 500 a -40c v dd = 5v (5) regulator enabled 230 500 a +25c 230 500 a +60c 240 600 a +85c 250 700 a +125c 31.2 dc characteristics: power-down and supply current pic18f66k80 family (industrial/extended) (continued) pic18f66k80 family (industrial/extended) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss , and all features that add delta current disabled (such as wdt, sosc oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: for lf devices, reten (config1l<0>) = 1 . 5: for f devices, sreten (wdtcon<4>) = 1 and reten (config1l<0>) = 0 .
? 2011 microchip technology inc. ds39977d-page 555 pic18f66k80 family supply current (i dd ) cont. (2,3) pic18 lf xxk80 2.3 4 ma -40c v dd = 3.3v (4) regulator disabled f osc = 64 mhz ( pri_idle mode, ec oscillator) 2.3 4 ma +25c 2.3 4 ma +60c 2.3 5 ma +85c 2.3 5 ma +125c pic18 f xxk80 2.3 4 ma -40c v dd = 3.3v (5) regulator enabled 2.3 4 ma +25c 2.3 4 ma +60c 2.3 5 ma +85c 2.3 5 ma +125c pic18 f xxk80 2.5 5 ma -40c v dd = 5v (5) regulator enabled 2.5 5 ma +25c 2.5 5 ma +60c 2.5 6 ma +85c 2.5 6 ma +125c 31.2 dc characteristics: power-down and supply current pic18f66k80 family (industrial/extended) (continued) pic18f66k80 family (industrial/extended) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss , and all features that add delta current disabled (such as wdt, sosc oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-r ail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: for lf devices, reten (config1l<0>) = 1 . 5: for f devices, sreten (wdtcon<4>) = 1 and reten (config1l<0>) = 0 .
pic18f66k80 family ds39977d-page 556 ? 2011 microchip technology inc. supply current (i dd ) cont. (2,3) pic18 lf xxk80 2 8 a -40c v dd = 1.8v (4) regulator disabled f osc = 32 khz (3) ( sec_run mode, soscsel = 01 ) 5 10 a +25c 6 15 a +60c 8 20 a +85c 13 30 a +125c pic18 lf xxk80 3 15 a -40c v dd = 3.3v (4) regulator disabled 16 22 a +25c 17 28 a +60c 19 39 a +85c 25 60 a +125c pic18 f xxk80 70 170 a -40c v dd = 3.3v (5) regulator enabled 70 170 a +25c 70 170 a +60c 75 180 a +85c 90 190 a +125c pic18 f xxk80 75 180 a -40c v dd = 5v (5) regulator enabled 75 180 a +25c 75 180 a +60c 80 190 a +85c 95 200 a +125c 31.2 dc characteristics: power-down and supply current pic18f66k80 family (industrial/extended) (continued) pic18f66k80 family (industrial/extended) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss , and all features that add delta current disabled (such as wdt, sosc oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: for lf devices, reten (config1l<0>) = 1 . 5: for f devices, sreten (wdtcon<4>) = 1 and reten (config1l<0>) = 0 .
? 2011 microchip technology inc. ds39977d-page 557 pic18f66k80 family supply current (i dd ) cont. (2,3) pic18 lf xxk80 1.4 4 a -40c v dd = 1.8v (4) regulator disabled f osc = 32 khz (3) ( sec_idle mode, soscsel = 01 ) 2.4 6 a +25c 3.6 10 a +60c 4.6 12 a +85c 9.0 20 a +125 pic18 lf xxk80 2 5 a -40c v dd = 3.3v (4) regulator disabled 10 18 a +25c 11 22 a +60c 13 30 a +85c 17 40 a +125 pic18 f xxk80 55 150 a +25c v dd = 3.3v (5) regulator enabled 55 150 a +60c 55 150 a +85c 60 160 a +125c 75 170 a +25c pic18 f xxk80 53 160 a -40c v dd = 5v (5) regulator enabled 62 160 a +25c 70 160 a +60c 85 170 a +85c 100 180 a +125c 31.2 dc characteristics: power-down and supply current pic18f66k80 family (industrial/extended) (continued) pic18f66k80 family (industrial/extended) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss , and all features that add delta current disabled (such as wdt, sosc oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-r ail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: for lf devices, reten (config1l<0>) = 1 . 5: for f devices, sreten (wdtcon<4>) = 1 and reten (config1l<0>) = 0 .
pic18f66k80 family ds39977d-page 558 ? 2011 microchip technology inc. d022 ?? i wdt ) module differential currents ( ? i wdt , ? i oscb , ? i ad ) watchdog timer pic18 lf xxk80 0.4 1 ? a -40c v dd = 1.8v regulator disabled 0.4 1 ? a +25c 0.5 1 ? a +60c 0.5 1 ? a +85c 0.5 2 ? a +125c pic18 lf xxk80 0.6 2 ? a -40c v dd = 3.3v regulator disabled 0.6 2 ? a +25c 0.7 2 ? a +60c 0.7 2 ? a +85c 13 ? a +125c pic18 f xxk80 0.6 2 ? a -40c v dd = 3.3v regulator enabled 0.6 2 ? a +25c 0.7 2 ? a +60c 0.7 2 ? a +85c 1 3 ? a +125c pic18 f xxk80 0.8 2 ? a -40c v dd = 5v regulator enabled 0.8 2 ? a +25c 0.9 2 ? a +60c 0.9 2 ? a +85c 1.5 4 ? a +125c 31.2 dc characteristics: power-down and supply current pic18f66k80 family (industrial/extended) (continued) pic18f66k80 family (industrial/extended) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss , and all features that add delta current disabled (such as wdt, sosc oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: for lf devices, reten (config1l<0>) = 1 . 5: for f devices, sreten (wdtcon<4>) = 1 and reten (config1l<0>) = 0 .
? 2011 microchip technology inc. ds39977d-page 559 pic18f66k80 family d022a ( ? i bor ) brown-out reset pic18 lf xxk80 4.6 19 ? a -40c v dd = 3.3v regulator disabled high-power bor 4.5 20 ? a +25c 4.7 20 ? a +60c 4.7 20 ? a +85c 4.7 20 ? a +125c pic18 f xxk80 4.6 19 ? a -40c v dd = 3.3v regulator enabled high-power bor 4.6 20 ? a +25c 4.7 20 ? a +60c 4.7 20 ? a +85c 4.7 20 ? a +125c pic18 f xxk80 4.2 20 ? a -40c v dd = 5v regulator enabled high-power bor 4.3 20 ? a +25c 4.4 20 ? a +60c 4.4 20 ? a +85c 4.4 20 ? a +125c 31.2 dc characteristics: power-down and supply current pic18f66k80 family (industrial/extended) (continued) pic18f66k80 family (industrial/extended) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss , and all features that add delta current disabled (such as wdt, sosc oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-r ail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: for lf devices, reten (config1l<0>) = 1 . 5: for f devices, sreten (wdtcon<4>) = 1 and reten (config1l<0>) = 0 .
pic18f66k80 family ds39977d-page 560 ? 2011 microchip technology inc. d022b ( ? i hlvd ) high/low-voltage detect pic18 lf xxk80 3.8 9 ? a -40c v dd = 1.8v regulator disabled 4.2 9 ? a +25c 4.3 10 ? a +60c 4.3 10 ? a +85c 4.3 10 ? a +125c pic18 lf xxk80 4.5 11 ? a -40c v dd = 3.3v regulator disabled 4.8 12 ? a +25c 4.8 12 ? a +60c 4.8 12 ? a +85c 4.8 12 ? a +125c pic18 f xxk80 3.8 11 ? a -40c v dd = 3.3v regulator enabled 4.2 12 ? a +25c 4.3 12 ? a +60c 4.3 12 ? a +85c 4.3 12 ? a +125c pic18 f xxk80 4.9 13 ? a -40c v dd = 5v regulator enabled 4.9 13 ? a +25c 4.9 13 ? a +60c 4.9 13 ? a +85c 4.9 13 ? a +125c 31.2 dc characteristics: power-down and supply current pic18f66k80 family (industrial/extended) (continued) pic18f66k80 family (industrial/extended) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss , and all features that add delta current disabled (such as wdt, sosc oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: for lf devices, reten (config1l<0>) = 1 . 5: for f devices, sreten (wdtcon<4>) = 1 and reten (config1l<0>) = 0 .
? 2011 microchip technology inc. ds39977d-page 561 pic18f66k80 family d026 ( ? i ad ) a/d converter pic18 lf xxk80 0.4 1 ? a -40c v dd = 1.8v regulator disabled a/d on, not converting 0.4 1 ? a +25c 0.4 1 ? a +60c 0.4 1 ? a +85c 0.6 1.5 ? a +125c pic18 lf xxk80 0.5 1 ? a -40c v dd = 3.3v regulator disabled a/d on, not converting 0.5 1 ? a +25c 0.5 1 ? a +60c 0.5 1 ? a +85c 0.8 2 ? a +125c pic18 f xxk80 0.5 1 ? a -40c v dd = 3.3v regulator enabled a/d on, not converting 0.5 1 ? a +25c 0.5 1 ? a +60c 0.5 1 ? a +85c 0.8 2 ? a +125c pic18 f xxk80 1 2 ? a -40c v dd = 5v regulator enabled a/d on, not converting 1 2 ? a +25c 1 2 ? a +60c 1 2 ? a +85c 1 3 ? a +125c 31.2 dc characteristics: power-down and supply current pic18f66k80 family (industrial/extended) (continued) pic18f66k80 family (industrial/extended) standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. device typ max units conditions legend: shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss , and all features that add delta current disabled (such as wdt, sosc oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-r ail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt enabled/disabled as specified. 3: standard, low-cost 32 khz crystals have an operating temperature range of -10c to +70c. extended temperature crystals are available at a much higher cost. 4: for lf devices, reten (config1l<0>) = 1 . 5: for f devices, sreten (wdtcon<4>) = 1 and reten (config1l<0>) = 0 .
pic18f66k80 family ds39977d-page 562 ? 2011 microchip technology inc. 31.3 dc characteristics: pic18f66k80 family (industrial) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c ?? t a ? +85c for industrial -40c ?? t a ? +125c for extended param no. symbol characteristic min max units conditions v il input low voltage all i/o ports: d031 schmitt trigger buffer v ss 0.2 v dd v1.8v ? v dd ?? 5.5v d031a rc3 and rc4 v ss 0.3 v dd vi 2 c? enabled d031b v ss 0.8 v smbus enabled d032 mclr v ss 0.2 v dd v d033 osc1 v ss 0.2 v dd v lp, xt, hs modes d033a d034 osc1 sosci v ss v ss 0.2 v dd 0.3 v dd v v ec modes v ih input high voltage all i/o ports: d041 schmitt trigger buffer 0.8 v dd v1.8v ? v dd ?? 5.5v d041a rc3 and rc4 0.7 v dd v dd vi 2 c enabled d041b 2.1 v dd v smbus enabled d042 mclr 0.8 v dd v dd v d043 osc1 0.9 v dd v dd v rc mode d043a d044 osc1 sosci 0.7 v dd 0.7 v dd v dd v dd v v hs mode i il input leakage current (1) d060 i/o ports 50 500 na v ss ?? v pin ?? v dd , pin at high-impedance d061 mclr ?500navss ?? v pin ?? v dd d063 osc1 ? 1 ? avss ?? v pin ?? v dd i pu weak pull-up current d070 weak pull-up current 50 400 ? av dd = 5.5v, v pin = v ss note 1: negative current is defined as current sourced by the pin.
? 2011 microchip technology inc. ds39977d-page 563 pic18f66k80 family 31.4 dc characteristics: ctmu current source specifications v ol output low voltage d080 i/o ports: porta, portb, portc ? 0.6 v i ol = 8.5 ma, v dd = 5.5v, -40 ? c to +125 ? c portd, porte, portf, portg ?0.6vi ol = 3.5 ma, v dd = 5.5v, -40 ? c to +125 ? c d083 osc2/clko (ec modes) ?0.6vi ol = 1.6 ma, v dd = 5.5v, -40 ? c to +125 ? c v oh output high voltage (1) d090 i/o ports: v porta, portb, portc v dd ? 0.7 ? v i oh = -3 ma, v dd = 5.5v, -40 ? c to +125 ? c portd, porte, portf, portg v dd ? 0.7 ? v i oh = -2 ma, v dd = 5.5v, -40 ? c to +125 ? c d092 osc2/clko (intosc, ec modes) v dd ? 0.7 ? v i oh = -1 ma, v dd = 5.5v, -40 ? c to +125 ? c capacitive loading specs on output pins d100 (4) cosc2 osc2 pin ? 20 pf in hs mode when external clock is used to drive osc1 d101 c io all i/o pins and osc2 ? 50 pf to meet the ac timing specifications d102 c b sclx, sdax ? 400 pf i 2 c? specification dc characteristics standard operating conditions: 1.8v to 5.5v operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. sym characteristic min typ (1) max units conditions i out 1 ctmu current source, base range ? 550 ? na ctmuicon<1:0> = 01 i out 2 ctmu current source, 10x range ?5.5? ? a ctmuicon<1:0> = 10 i out 3 ctmu current source, 100x range ?55? ? a ctmuicon<1:0> = 11 note 1: nominal value at center point of current trim range (ctmuicon<7:2> = 000000 ). 31.3 dc characteristics: pic18f66k80 family (industrial) (continued) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c ?? t a ? +85c for industrial -40c ?? t a ? +125c for extended param no. symbol characteristic min max units conditions note 1: negative current is defined as current sourced by the pin.
pic18f66k80 family ds39977d-page 564 ? 2011 microchip technology inc. table 31-1: memory programming requirements dc characteristics standard operating conditions operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. sym characteristic min typ? max units conditions internal program memory programming specifications (1) d110 v pp voltage on mclr /v pp /re5 pin v dd + 1.5 ? 10 v (note 3, note 4) d113 i ddp supply current during programming ??10ma data eeprom memory (note 2) d120 e d byte endurance 100k 1000k ? e/w -40 ? c to +125 ? c d121 v drw v dd for read/write 1.8 ? 5.5 v using eecon to read/write pic18fxxkxx devices 1.8 ? 3.6 v using eecon to read/write pic18lfxxkxx devices d122 t dew erase/write cycle time ? 4 ? ms d123 t retd characteristic retention 20 ? ? year provided no other specifications are violated d124 t ref number of total erase/write cycles before refresh (2) 1m 10m ? e/w -40c to +125c program flash memory d130 e p cell endurance 1k 10k ? e/w -40 ? c to +125 ? c d131 v pr v dd for read 1.8 ? 5.5 v pic18fxxkxx devices 1.8 ? 3.6 v pic18lfxxkxx devices d132b v pew voltage for self-timed erase or write operations v dd 1.8 ? 5.5 v pic18fxxkxx devices d133a t iw self-timed write cycle time ? 2 ? ms d134 t retd characteristic retention 20 ? ? year provided no other specifications are violated d135 i ddp supply current during programming ??10ma d140 t we writes per erase cycle ? ? 1 for each physical address ? data in ?typ? column is at 3.3v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: these specifications are for programming the on-chip program memory through the use of table write instructions. 2: refer to section 8.8 ?using the data eeprom? for a more detailed discussion on data eeprom endurance. 3: required only if single-supply programming is disabled. 4: the mplab icd2 does not support variable v pp output. circuitry to limit the icd2 v pp voltage must be placed between the icd2 and target system when programming or debugging with the icd2.
? 2011 microchip technology inc. ds39977d-page 565 pic18f66k80 family table 31-2: comparator specifications table 31-3: voltage reference specifications table 31-4: internal voltag e regulator specifications operating conditions: 1.8v ? v dd ? 5.5v, -40c ? t a ? +125c param no. sym characteristics min typ max units comments d300 v ioff input offset voltage ? 5.0 40 mv d301 v icm input common mode voltage ? ? av dd ? 1.5 v d302 cmrr common mode rejection ratio 55 ? ? db d303 t resp response time (1) ?150400 ns d304 t mc 2 ov comparator mode change to output valid* ?? 10 ? s note 1: response time measured with one comparator input at (av dd ? 1.5)/2, while the other input transitions from v ss to v dd . operating conditions: 1.8v ? v dd ? 5.5v, -40c ? t a ? +125c param no. sym characteristics min typ max units comments d310 v res resolution v dd /24 ? v dd /32 lsb d311 vr aa absolute accuracy ? ? 1/2 lsb d312 vr ur unit resistor value (r) ? 2k ? ? d313 t set settling time (1) ? ? 10 ? s note 1: settling time measured while cvrr = 1 and cvr<3:0> transitions from ? 0000 ? to ? 1111 ?. operating conditions: -40c ? t a ? +125c param no. sym characteristics min typ max units comments v rgout regulator output voltage ? 3.3 ? v c efc external filter capacitor value 4.7 10 ? ? f capacitor must be low-esr, a low series resistance (< 5 ? )
pic18f66k80 family ds39977d-page 566 ? 2011 microchip technology inc. 31.5 ac (timing) characteristics 31.5.1 timing parameter symbology the timing parameter symbols have been created following one of the following formats: 1. tpps2pps 3. t cc : st (i 2 c specifications only) 2. tpps 4. ts (i 2 c specifications only) t f frequency t time lowercase letters (pp) and their meanings: pp cc ccp1 osc osc1 ck clko rd rd cs cs rw rd or wr di sdi sc sck do sdo ss ss dt data in t0 t0cki io i/o port t1 t1cki mc mclr wr wr uppercase letters and their meanings: s f fall p period hhigh rrise i invalid (high-impedance) v valid l low z high-impedance i 2 c only aa output access high high buf bus free low low t cc : st (i 2 c specifications only) cc hd hold su setup st dat data input hold sto stop condition sta start condition
? 2011 microchip technology inc. ds39977d-page 567 pic18f66k80 family 31.5.2 timing conditions the temperature and voltages specified in tab l e 3 1- 5 apply to all timing specifications unless otherwise noted. figure 31-3 specifies the load conditions for the timing specifications. table 31-5: temperature and voltage specifications ? ac figure 31-3: load conditions for device timing specifications ac characteristics standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ?? +85c for industrial -40c ? t a ?? +125c for extended operating voltage v dd range as described in section 31.1 and section 31.3 . v dd /2 c l r l pin pin v ss v ss c l r l = 464 ? c l = 50 pf for all pins except osc2/clko/ra6 and including d and e outputs as ports c l = 15 pf for osc2/clko/ra6 load condition 1 load condition 2
pic18f66k80 family ds39977d-page 568 ? 2011 microchip technology inc. 31.5.3 timing diagrams and specifications figure 31-4: external clock timing table 31-6: external clock timing requirements param. no. symbol characteristic min max units conditions 1a f osc external clkin frequency (1) dc 64 mhz ec, ecio oscillator mode oscillator frequency (1) dc 4 mhz rc oscillator mode 0.1 4 mhz xt oscillator mode 4 16 mhz hs oscillator mode 4 16 mhz hs + pll oscillator mode 5 33 khz lp oscillator mode 1t osc external clkin period (1) 15.6 ? ns ec, ecio oscillator mode oscillator period (1) 250 ? ns rc oscillator mode 250 10,000 ns xt oscillator mode 40 62.5 250 250 ns ns hs oscillator mode hs + pll oscillator mode 5200 ? s lp oscillator mode 2t cy instruction cycle time (1) 62.5 ? ns t cy = 4/f osc 3t os l, t os h external clock in (osc1) high or low time 30 ? ns xt oscillator mode 2.5 ? ? s lp oscillator mode 10 ? ns hs oscillator mode 4t os r, t os f external clock in (osc1) rise or fall time ? 20 ns xt oscillator mode ? 50 ns lp oscillator mode ? 7.5 ns hs oscillator mode note 1: instruction cycle period (t cy ) equals four times the input oscillator time base period for all configurations except pll. all specified values are based on characterization data for that particular oscillator type under standard operating conditions with the device executing code. exceeding these specified limits may result in an unstable oscillator operation and/or higher than expected current consumption. all devices are tested to operate at ?min.? values with an external clock applied to the osc1/clkin pin. when an external clock input is used, the ?max.? cycle time limit is ?dc? (no clock) for all devices. osc1 clko q4 q1 q2 q3 q4 q1 1 2 3 3 4 4
? 2011 microchip technology inc. ds39977d-page 569 pic18f66k80 family table 31-7: pll clock timing specifications (v dd = 1.8v to 5.5v) table 31-8: internal rc accuracy (intosc) param no. sym characteristic min typ max units conditions f10 f osc oscillator frequency range 4 ? 5 mhz v dd = 1.8-5.5v 4?16mhzv dd = 3.0-5.5v, -40c to +125c f11 f sys on-chip vco system frequency 16 ? 20 mhz v dd = 1.8-5.5v 16 ? 64 mhz v dd = 3.0-5.5v, -40c to +125c f12 t rc pll start-up time (lock time) ? ? 2 ms f13 ? clk clkout stability (jitter) -2 ? +2 % pic18f66k80 family standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +125c param no. min typ max units conditions oa1 hfintosc/mfintosc accuracy @ freq = 16 mhz, 8 mhz, 4 mhz, 2 mhz, 1 mhz, 500 khz, 250 khz (1) -2 ? +2 % +25c v dd = 3-5.5v -5 ? +5 % -40c to +85c v dd = 1.8-5.5v -10 ? +10 % -40c to +125c v dd = 1.8-5.5v oa2 lfintosc accuracy @ freq = 31 khz -15 ? 15 % -40c to +125c v dd = 1.8-5.5v note 1: frequency calibrated at 25c. osctune register can be used to compensate for temperature drift.
pic18f66k80 family ds39977d-page 570 ? 2011 microchip technology inc. figure 31-5: clko and i/o timing table 31-9: clko and i/o timing requirements param no. symbol characteristic min typ max units conditions 10 t os h2 ck losc1 ? to clko ? ?75200ns (note 1) 11 t os h2 ck hosc1 ? to clko ? ?75200ns (note 1) 12 t ck rclko rise time ? 15 30 ns (note 1) 13 t ck f clko fall time ? 15 30 ns (note 1) 14 t ck l2 io vclko ? to port out valid ? ? 0.5 t cy + 20 ns 15 t io v2 ck h port in valid before clko ? 0.25 t cy + 25 ? ? ns 16 t ck h2 io i port in hold after clko ? 0??ns 17 t os h2 io vosc1 ? (q1 cycle) to port out valid ? 50 150 ns 18 t os h2 io iosc1 ? (q2 cycle) to port input invalid (i/o in hold time) 100 ? ? ns 19 t io v2 os h port input valid to osc1 ?? (i/o in setup time) 0??ns 20 t io r port output rise time ? 10 25 ns 21 t io f port output fall time ? 10 25 ns 22? t inp intx pin high or low time 20 ? ? ns 23? t rbp rb<7:4> change intx high or low time t cy ??ns ? these parameters are asynchronous events not related to any internal clock edges. note 1: measurements are taken in ec mode, where clko output is 4 x t osc . note: refer to figure 31-3 for load conditions. osc1 clko i/o pin (input) i/o pin (output) q4 q1 q2 q3 10 13 14 17 20, 21 19 18 15 11 12 16 old value new value
? 2011 microchip technology inc. ds39977d-page 571 pic18f66k80 family table 31-10: clko and i/o timing requirements figure 31-6: reset, watchdog timer, oscillator start-up timer and power-up timer timing param. no symbol characteristics min typ max units 150 tadv2all address out valid to ale ?? (address setup time) 0.25 t cy ? 10 ? ? ns 151 tall2adl ale ? to address out invalid (address hold time) 5??ns 155 tall2oel ale ?? to oe ? 10 0.125 t cy ?ns 160 tadz2oel ad high-z to oe ?? (bus release to oe )0??ns 161 toeh2add oe ? to ad driven 0.125 t cy ? 5 ? ? ns 162 tadv2oeh ls data valid before oe ?? (data setup time) 20 ? ? ns 163 toeh2adl oe ? to data in invalid (data hold time) 0 ? ? ns 164 talh2all ale pulse width ? 0.25 t cy ?ns 165 toel2oeh oe pulse width 0.5 t cy ? 5 0.5 t cy ?ns 166 talh2alh ale ? to ale ? (cycle time) ? t cy ?ns 167 tacc address valid to data valid 0.75 t cy ? 25 ? ? ns 168 to e o e ? to data valid ? 0.5 t cy ? 25 ns 169 tall2oeh ale ?? to oe ? 0.625 t cy ? 10 ? 0.625 t cy + 10 ns 171 talh2csl chip enable active to ale ? 0.25 t cy ? 20 ? ? ns 171a tubl2oeh ad valid to chip enable active ? ? 10 ns v dd mclr internal por pwrt time-out oscillator time-out internal reset watchdog timer reset 33 32 30 31 34 i/o pins 34 note: refer to figure 31-3 for load conditions.
pic18f66k80 family ds39977d-page 572 ? 2011 microchip technology inc. figure 31-7: brown-out reset timing table 31-11: reset, watchdog timer, oscillator start-up timer, power-up timer and brown-out reset requirements param. no. symbol characteristic min typ max units conditions 30 tmcl mclr pulse width (low) 2 ? ? ? s 31 t wdt watchdog timer time-out period (no postscaler) ?4.00? ms 32 t ost oscillation start-up timer period 1024 t osc ? 1024 t osc ?t osc = osc1 period 33 t pwrt power-up timer period ? 65.5 ? ms 34 t ioz i/o high-impedance from mclr low or watchdog timer reset ?2? ? s 35 t bor brown-out reset pulse width 200 ? ? ? sv dd ? bv dd (see d005) 36 t ivrst time for internal reference voltage to become stable ?25? ? s 37 t hlvd high/low-voltage detect pulse width 200 ? ? ? sv dd ? v hlvd 38 t csd cpu start-up time 5 ? 10 ? s 39 t iobst time for intosc to stabilize ? 1 ? ? s v dd bv dd 35 v bgap = 1.2v v irvst enable internal internal reference 36 reference voltage voltage stable
? 2011 microchip technology inc. ds39977d-page 573 pic18f66k80 family figure 31-8: high/low-volta ge detect characteristics table 31-12: high/low-voltage detect characteristics standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ?? +125c for extended param no. sym characteristic min typ max units conditions d420 hlvd voltage on v dd transition high-to-low hlvdl<3:0> = 0000 1.80 1.85 1.90 v hlvdl<3:0> = 0001 2.03 2.08 2.13 v hlvdl<3:0> = 0010 2.24 2.29 2.35 v hlvdl<3:0> = 0011 2.40 2.46 2.53 v hlvdl<3:0> = 0100 2.50 2.56 2.62 v hlvdl<3:0> = 0101 2.70 2.77 2.84 v hlvdl<3:0> = 0110 2.82 2.89 2.97 v hlvdl<3:0> = 0111 2.95 3.02 3.10 v hlvdl<3:0> = 1000 3.24 3.32 3.41 v hlvdl<3:0> = 1001 3.42 3.50 3.59 v hlvdl<3:0> = 1010 3.61 3.70 3.79 v hlvdl<3:0> = 1011 3.82 3.91 4.10 v hlvdl<3:0> = 1100 4.06 4.16 4.26 v hlvdl<3:0> = 1101 4.33 4.44 4.55 v hlvdl<3:0> = 1110 4.64 4.75 4.87 v v hlvd hlvdif v dd (hlvdif set by hardware) (hlvdif can be cleared in software) v hlvd for vdirmag = 1 : for vdirmag = 0 : v dd
pic18f66k80 family ds39977d-page 574 ? 2011 microchip technology inc. figure 31-9: timer0 and timer1 external clock timings table 31-13: timer0 and timer1 external clock requirements param no. symbol characteristic min max units conditions 40 t t 0h t0cki high pulse width no prescaler 0.5 t cy + 20 ? ns with prescaler 10 ? ns 41 t t 0l t0cki low pulse width no prescaler 0.5 t cy + 20 ? ns with prescaler 10 ? ns 42 t t 0p t0cki period no prescaler t cy + 10 ? ns with prescaler greater of: 20 ns or (t cy + 40)/n ?nsn = prescale value (1, 2, 4,..., 256) 45 t t 1h t1cki high time synchronous, no prescaler 0.5 t cy + 20 ? ns synchronous, with prescaler 10 ? ns asynchronous 30 ? ns 46 t t 1l t1cki low time synchronous, no prescaler 0.5 t cy + 5 ? ns synchronous, with prescaler 10 ? ns asynchronous 30 ? ns 47 t t 1p t1cki input period synchronous greater of: 20 ns or (t cy + 40)/n ?nsn = prescale value (1, 2, 4, 8) asynchronous 60 ? ns f t 1 t1cki oscillator input frequency range dc 50 khz 48 t cke 2 tmr i delay from external t1cki clock edge to timer increment 2 t osc 7 t osc ? note: refer to figure 31-3 for load conditions. 46 47 45 48 41 42 40 txcki sosco/sclki tmr0 or tmr1
? 2011 microchip technology inc. ds39977d-page 575 pic18f66k80 family figure 31-10: capture/compare/pwm timi ngs (eccp1, eccp2 modules) table 31-14: capture/compare/pwm requirements (eccp1, eccp2 modules) param no. symbol characteristic min max units conditions 50 t cc l ccpx input low time no prescaler 0.5 t cy + 20 ? ns with prescaler 10 ? ns 51 t cc h ccpx input high time no prescaler 0.5 t cy + 20 ? ns with prescaler 10 ? ns 52 t cc p ccpx input period 3 t cy + 40 n ? ns n = prescale value (1, 4 or 16) 53 t cc r ccpx output fall time ? 25 ns 54 t cc f ccpx output fall time ? 25 ns note: refer to figure 31-3 for load conditions. ccpx (capture mode) 50 51 52 ccpx 53 54 (compare or pwm mode)
pic18f66k80 family ds39977d-page 576 ? 2011 microchip technology inc. figure 31-11: example spi master mode timing (cke = 0 ) table 31-15: example spi mode requirements (master mode, cke = 0 ) param no. symbol characteristic min max units conditions 73 t di v2 sc h, t di v2 sc l setup time of sdix data input to sckx edge 20 ? ns 73a t b 2 b last clock edge of byte 1 to the 1st clock edge of byte 2 1.5 t cy + 40 ? ns 74 t sc h2 di l, t sc l2 di l hold time of sdix data input to sckx edge 40 ? ns 75 t do r sdox data output rise time ? 25 ns 76 t do f sdox data output fall time ? 25 ns 78 t sc r sckx output rise time (master mode) ? 25 ns 79 t sc f sckx output fall time (master mode) ? 25 ns 80 t sc h2 do v, t sc l2 do v sdox data output valid after sckx edge ? 50 ns sckx (ckpx = 0 ) sckx (ckpx = 1 ) sdox sdix 73 74 75, 76 78 79 80 79 78 msb lsb bit 6 - - - - - - 1 lsb in bit 6 - - - - 1 note: refer to figure 31-3 for load conditions. msb in
? 2011 microchip technology inc. ds39977d-page 577 pic18f66k80 family figure 31-12: example spi master mode timing (cke = 1 ) table 31-16: example spi mode requirements (master mode, cke = 1 ) param. no. symbol characteristic min max units conditions 73 t di v2 sc h, t di v2 sc l setup time of sdix data input to sckx edge 20 ? ns 73a t b 2 b last clock edge of byte 1 to the 1st clock edge of byte 2 1.5 t cy + 40 ? ns 74 t sc h2 di l, t sc l2 di l hold time of sdix data input to sckx edge 40 ? ns 75 t do r sdox data output rise time ? 25 ns 76 t do f sdox data output fall time ? 25 ns 78 t sc r sckx output rise time (master mode) ? 25 ns 79 t sc f sckx output fall time (master mode) ? 25 ns 80 t sc h2 do v, t sc l2 do v sdox data output valid after sckx edge ? 50 ns 81 t do v2 sc h, t do v2 sc l sdox data output setup to sckx edge t cy ?ns sckx (ckpx = 0 ) sckx (ckpx = 1 ) sdox sdix 81 74 75, 76 78 80 msb 79 73 bit 6 - - - - - - 1 lsb in bit 6 - - - - 1 lsb note: refer to figure 31-3 for load conditions. msb in
pic18f66k80 family ds39977d-page 578 ? 2011 microchip technology inc. figure 31-13: example spi slave mode timing (cke = 0 ) table 31-17: example spi mode requirements (slave mode timing, cke = 0 ) param no. symbol characteristic min max units conditions 70 t ss l2 sc h, t ss l2 sc l ssx ? to sckx ? or sckx ? input 3 t cy ?ns 70a t ss l2wb ssx to write to sspbuf 3 t cy ?ns 71 t sc h sckx input high time (slave mode) continuous 1.25 t cy + 30 ? ns 71a single byte 40 ? ns (note 1) 72 t sc l sckx input low time (slave mode) continuous 1.25 t cy + 30 ? ns 72a single byte 40 ? ns (note 1) 73 t di v2 sc h, t di v2 sc l setup time of sdix data input to sckx edge 20 ? ns 73a t b 2 b last clock edge of byte 1 to the first clock edge of byte 2 1.5 t cy + 40 ? ns (note 2) 74 t sc h2 di l, t sc l2 di l hold time of sdix data input to sckx edge 40 ? ns 75 t do r sdox data output rise time ? 25 ns 76 t do f sdox data output fall time ? 25 ns 77 t ss h2 do z ssx ? to sdox output high-impedance 10 50 ns 78 t sc r sckx output rise time (master mode) ? 25 ns 79 t sc f sckx output fall time (master mode) ? 25 ns 80 t sc h2 do v, t sc l2 do v sdox data output valid after sckx edge ? 50 ns 83 t sc h2 ss h, t sc l2 ss h ssx ? after sckx edge 1.5 t cy + 40 ? ns note 1: requires the use of parameter #73a. 2: only if parameter #71a and #72a are used. ssx sckx (ckpx = 0 ) sckx (ckp = 1 ) sdox sdix 70 71 72 73 74 75, 76 77 78 79 80 79 78 msb lsb bit 6 - - - - - - 1 bit 6 - - - - 1 lsb in 83 note: refer to figure 31-3 for load conditions. msb in
? 2011 microchip technology inc. ds39977d-page 579 pic18f66k80 family figure 31-14: example spi slave mode timing (cke = 1 ) table 31-18: example spi slave mode requirements (cke = 1 ) param no. symbol characteristic min max units conditions 70 t ss l2 sc h, t ss l2 sc l ssx ? to sckx ? or sckx ? input 3 t cy ?ns 70a t ss l2wb ssx to write to sspbuf 3 t cy ?ns 71 t sc h sckx input high time (slave mode) continuous 1.25 t cy + 30 ? ns 71a single byte 40 ? ns (note 1) 72 t sc l sckx input low time (slave mode) continuous 1.25 t cy + 30 ? ns 72a single byte 40 ? ns (note 1) 73a t b 2 b last clock edge of byte 1 to the first clock edge of byte 2 1.5 t cy + 40 ? ns (note 2) 74 t sc h2 di l, t sc l2 di l hold time of sdix data input to sckx edge 40 ? ns 75 t do r sdox data output rise time ? 25 ns 76 t do f sdox data output fall time ? 25 ns 77 t ss h2 do z ssx ? to sdox output high-impedance 10 50 ns 78 t sc r sckx output rise time (master mode) ? 25 ns 79 t sc f sckx output fall time (master mode) ? 25 ns 80 t sc h2 do v, t sc l2 do v sdox data output valid after sckx edge ? 50 ns 82 t ss l2 do v sdox data output valid after ssx ? edge ? 50 ns 83 t sc h2 ss h, t sc l2 ss h ssx ? after sckx edge 1.5 t cy + 40 ? ns note 1: requires the use of parameter #73a. 2: only if parameter #71a and #72a are used. ssx sckx (ckpx = 0 ) sckx (ckpx = 1 ) sdox sdix 70 71 72 82 74 75, 76 msb bit 6 - - - - - - 1 lsb 77 bit 6 - - - - 1 lsb in 80 83 note: refer to figure 31-3 for load conditions. msb in
pic18f66k80 family ds39977d-page 580 ? 2011 microchip technology inc. figure 31-15: i 2 c? bus start/stop bits timing table 31-19: i 2 c? bus start/stop bits requirements (slave mode) param. no. symbol characteristic min max units conditions 90 t su : sta start condition 100 khz mode 4700 ? ns only relevant for repeated start condition setup time 400 khz mode 600 ? 91 t hd : sta start condition 100 khz mode 4000 ? ns after this period, the first clock pulse is generated hold time 400 khz mode 600 ? 92 t su : sto stop condition 100 khz mode 4700 ? ns setup time 400 khz mode 600 ? 93 t hd : sto stop condition 100 khz mode 4000 ? ns hold time 400 khz mode 600 ? note: refer to figure 31-3 for load conditions. 91 92 93 sclx sdax start condition stop condition 90
? 2011 microchip technology inc. ds39977d-page 581 pic18f66k80 family figure 31-16: i 2 c? bus data timing table 31-20: i 2 c? bus data requirements (slave mode) param. no. symbol characteristic min max units conditions 100 t high clock high time 100 khz mode 4.0 ? ? s 400 khz mode 0.6 ? ? s mssp module 1.5 t cy ? 101 t low clock low time 100 khz mode 4.7 ? ? s 400 khz mode 1.3 ? ? s mssp module 1.5 t cy ? 102 t r sdax and sclx rise time 100 khz mode ? 1000 ns 400 khz mode 20 + 0.1 c b 300 ns c b is specified to be from 10 to 400 pf 103 t f sdax and sclx fall time 100 khz mode ? 300 ns 400 khz mode 20 + 0.1 c b 300 ns c b is specified to be from 10 to 400 pf 90 t su : sta start condition setup time 100 khz mode 4.7 ? ? s only relevant for repeated start condition 400 khz mode 0.6 ? ? s 91 t hd : sta start condition hold time 100 khz mode 4.0 ? ? s after this period, the first clock pulse is generated 400 khz mode 0.6 ? ? s 106 t hd : dat data input hold time 100 khz mode 0 ? ns 400 khz mode 0 0.9 ? s 107 t su : dat data input setup time 100 khz mode 250 ? ns (note 2) 400 khz mode 100 ? ns 92 t su : sto stop condition setup time 100 khz mode 4.7 ? ? s 400 khz mode 0.6 ? ? s 109 t aa output valid from clock 100 khz mode ? 3500 ns (note 1) 400 khz mode ? ? ns 110 t buf bus free time 100 khz mode 4.7 ? ? s time the bus must be free before a new transmission can start 400 khz mode 1.3 ? ? s d102 c b bus capacitive loading ? 400 pf note 1: as a transmitter, the device must provide this internal mi nimum delay time to bridge the undefined region (min. 300 ns) of the falling edge of sclx to avoid unintended generation of start or stop conditions. 2: a fast mode i 2 c? bus device can be used in a standard mode i 2 c bus system, but the requirement, t su : dat ? 250 ns, must then be met. this will automatically be the case if the device does not stretch the low period of the sclx signal. if such a device does stretch the low period of the sclx si gnal, it must output the next data bit to the sdax line, t r max. + t su : dat = 1000 + 250 = 1250 ns (according to the standard mode i 2 c bus specification), before the sclx line is released. note: refer to figure 31-3 for load conditions. 90 91 92 100 101 103 106 107 109 109 110 102 sclx sdax in sdax out
pic18f66k80 family ds39977d-page 582 ? 2011 microchip technology inc. figure 31-17: mssp i 2 c? bus start/stop bits timing waveforms table 31-21: mssp i 2 c? bus start/stop bits requirements figure 31-18: mssp i 2 c? bus data timing param. no. symbol characteristic min max units conditions 90 t su : sta start condition 100 khz mode 2(t osc )(brg + 1) ? ns only relevant for repeated start condition setup time 400 khz mode 2(t osc )(brg + 1) ? 1 mhz mode (1) 2(t osc )(brg + 1) ? 91 t hd : sta start condition 100 khz mode 2(t osc )(brg + 1) ? ns after this period, the first clock pulse is generated hold time 400 khz mode 2(t osc )(brg + 1) ? 1 mhz mode (1) 2(t osc )(brg + 1) ? 92 t su : sto stop condition 100 khz mode 2(t osc )(brg + 1) ? ns setup time 400 khz mode 2(t osc )(brg + 1) ? 1 mhz mode (1) 2(t osc )(brg + 1) ? 93 t hd : sto stop condition 100 khz mode 2(t osc )(brg + 1) ? ns hold time 400 khz mode 2(t osc )(brg + 1) ? 1 mhz mode (1) 2(t osc )(brg + 1) ? note 1: maximum pin capacitance = 10 pf for all i 2 c? pins. note: refer to figure 31-3 for load conditions. 91 93 sclx sdax start condition stop condition 90 92 note: refer to figure 31-3 for load conditions. 90 91 92 100 101 103 106 107 109 109 110 102 sclx sdax in sdax out
? 2011 microchip technology inc. ds39977d-page 583 pic18f66k80 family table 31-22: mssp i 2 c? bus data requirements param. no. symbol characteristic min max units conditions 100 t high clock high time 100 khz mode 2(t osc )(brg + 1) ? ? 400 khz mode 2(t osc )(brg + 1) ? ? 1 mhz mode (1) 2(t osc )(brg + 1) ? ? 101 t low clock low time 100 khz mode 2(t osc )(brg + 1) ? ? 400 khz mode 2(t osc )(brg + 1) ? ? 1 mhz mode (1) 2(t osc )(brg + 1) ? ? 102 t r sdax and sclx rise time 100 khz mode ? 1000 ns c b is specified to be from 10 to 400 pf 400 khz mode 20 + 0.1 c b 300 ns 1 mhz mode (1) ? 300 ns 103 t f sdax and sclx fall time 100 khz mode ? 300 ns c b is specified to be from 10 to 400 pf 400 khz mode 20 + 0.1 c b 300 ns 1 mhz mode (1) ? 100 ns 90 t su : sta start condition setup time 100 khz mode 2(t osc )(brg + 1) ? ? only relevant for repeated start condition 400 khz mode 2(t osc )(brg + 1) ? ? 1 mhz mode (1) 2(t osc )(brg + 1) ? ? 91 t hd : sta start condition hold time 100 khz mode 2(t osc )(brg + 1) ? ? after this period, the first clock pulse is generated 400 khz mode 2(t osc )(brg + 1) ? ? 1 mhz mode (1) 2(t osc )(brg + 1) ? ? 106 t hd : dat data input hold time 100 khz mode 0 ? ? 400 khz mode 0 0.9 ? s 1 mhz mode (1) ? ? sns 107 t su : dat data input setup time 100 khz mode 250 ? ns (note 2) 400 khz mode 100 ? ns 1 mhz mode (1) ??ns 92 t su : sto stop condition setup time 100 khz mode 2(t osc )(brg + 1) ? ? 400 khz mode 2(t osc )(brg + 1) ? ? 1 mhz mode (1) 2(t osc )(brg + 1) ? ? 109 t aa output valid from clock 100 khz mode ? 3500 ns 400 khz mode ? 1000 ns 1 mhz mode (1) ??ns 110 t buf bus free time 100 khz mode 4.7 ? ? s time the bus must be free before a new transmission can start 400 khz mode 1.3 ? ? s 1 mhz mode (1) ?? ? s d102 c b bus capacitive loading ? 400 pf note 1: maximum pin capacitance = 10 pf for all i 2 c? pins. 2: a fast mode i 2 c bus device can be used in a standard mode i 2 c bus system, but parameter #107 ? 250 ns must then be met. this will automatically be the case if the device does not stretch the low period of the sclx signal. if such a device does stretch the low period of the sclx signal, it must output the next data bit to the sdax line, parameter #102 + parameter #107 = 1000 + 250 = 1250 ns (for 100 khz mode), before the sclx line is released.
pic18f66k80 family ds39977d-page 584 ? 2011 microchip technology inc. figure 31-19: eusart synchronous transmission (master/slave) timing table 31-23: eusart/ausart synchronous transmission requirements figure 31-20: eusart/ausart synchronous receive (master/slave) timing table 31-24: eusart/ausart synchronous receive requirements param no. symbol characteristic min max units conditions 120 t ck h2 dt v sync xmit (master and slave) clock high to data out valid ? 40 ns 121 t ckrf clock out rise time and fall time (master mode) ? 20 ns 122 t dtrf data out rise time and fall time ? 20 ns param. no. symbol characteristic min max units conditions 125 t dt v2 ckl sync rcv (master and slave) data hold before ckx ? (dtx hold time) 10 ? ns 126 t ck l2 dtl data hold after ckx ? (dtx hold time) 15 ? ns 121 121 120 122 txx/ckx rxx/dtx pin pin note: refer to figure 31-3 for load conditions. 125 126 txx/ckx rxx/dtx pin pin note: refer to figure 31-3 for load conditions.
? 2011 microchip technology inc. ds39977d-page 585 pic18f66k80 family table 31-25: a/d converter characteristics: pic18f66k80 family (industrial/extended) param no. sym characteristic min typ max units conditions a01 n r resolution ? ? 12 bit ? v ref ? 3.0v a03 e il integral linearity error ? <1 2.0 lsb v dd = 3.0v ( ? v ref ?? 3.0v) ??2.0lsbv dd = 5.0v a04 e dl differential linearity error ? <1 +1.5/-1.0 lsb v dd = 3.0v ( ? v ref ?? 3.0v) ??+1.5/-1.0lsbv dd = 5.0v a06 e off offset error ? <1 5 lsb v dd = 3.0v ( ? v ref ?? 3.0v) ??3lsbv dd = 5.0v a07 e gn gain error ? <1 1.25 lsb v dd = 3.0v ( ? v ref ?? 3.0v) ??2.00lsbv dd = 5.0v a10 ? monotonicity guaranteed (1) ?v ss ? v ain ? v ref a20 ? v ref reference voltage range (v refh ? v refl ) 3?v dd ? v ss v for 12-bit resolution a21 v refh reference voltage high av ss + 3.0v ? av dd + 0.3v v for 12-bit resolution a22 v refl reference voltage low av ss ? 0.3v ? av dd ? 3.0v v for 12-bit resolution a25 v ain analog input voltage v refl ?v refh v a28 av dd analog supply voltage v dd ? 0.3 ? v dd + 0.3 v a29 av ss analog supply voltage v ss ? 0.3 ? v ss + 0.3 v a30 z ain recommended impedance of analog voltage source ??2.5k ? a50 i ref v ref input current (2) ? ? ? ? 5 150 ? a ? a during v ain acquisition. during a/d conversion cycle. note 1: the a/d conversion result never decreases with an increase in the input voltage and has no missing codes. 2: v refh current is from the ra3/an3/v ref + pin or v dd , whichever is selected as the v refh source. v refl current is from the ra2/an2/v ref -/cv ref pin or v ss , whichever is selected as the v refl source.
pic18f66k80 family ds39977d-page 586 ? 2011 microchip technology inc. figure 31-21: a/d conversion timing table 31-26: a/d conversion requirements param no. symbol characteristic min max units conditions 130 t ad a/d clock period 0.8 12.5 (1) ? st osc based, v ref ? 3.0v 1.4 25 (1) ? sv dd = 3.0v; t osc based, v ref full range ? 1 ? s a/d rc mode ?3 ? sv dd = 3.0v; a/d rc mode 131 t cnv conversion time (not including acquisition time) (2) 14 15 t ad 132 t acq acquisition time (3) 1.4 ? ? s -40c to +125c 135 t swc switching time from convert ? sample ? (note 4) tbd t dis discharge time 0.2 ? ? s -40c to +125c note 1: the time of the a/d clock period is dependent on the device frequency and the t ad clock divider. 2: adres registers may be read on the following t cy cycle. 3: the time for the holding capacitor to acquire the ?new? input voltage when the voltage changes full scale after the conversion (v dd to v ss or v ss to v dd ). the source impedance ( r s ) on the input channels is 50 ? . 4: on the following cycle of the device clock. 131 130 132 bsf adcon0, go q4 a/d clk a/d data adres adif go sample old_data sampling stopped done new_data (note 2) 11 10 9 2 1 0 note 1: if the a/d clock source is selected as rc, a time of t cy is added before the a/d clock starts. this allows the sleep instruction to be executed. 2: this is a minimal rc delay (typically 100 ns), which also disconnects the holding capacitor from the analog input. . . . . . . t cy (note 1)
? 2011 microchip technology inc. ds39977d-page 587 pic18f66k80 family 32.0 packaging information 32.1 package marking information legend: xx...x customer-specific information y year code (last digit of calendar year) yy year code (last 2 digits of calendar year) ww week code (week of january 1 is week ?01?) nnn alphanumeric traceability code pb-free jedec designator for matte tin (sn) * this package is pb-free. the pb-free jedec designator ( ) can be found on the outer packaging for this package. note : in the event the full microchip part number cannot be marked on one line, it will be carried over to the next line, thus limiting the number of available characters for customer-specific information. 3 e 3 e 28-lead qfn xxxxxxxx xxxxxxxx yywwnnn example 18f25k80 /mm 1010017 28-lead soic xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx yywwnnn example pic18f26k80/so 1010017 28-lead spdip xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx yywwnnn example pic18f26k80-i/sp 1010017 28-lead ssop xxxxxxxxxxxx xxxxxxxxxxxx yywwnnn example pic18f26k80 -i/ss 1010017 3 e 3 e 3 e 3 e
pic18f66k80 family ds39977d-page 588 ? 2011 microchip technology inc. 32.1 package marking information (continued) 40-lead pdip xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx yywwnnn example pic18f45k80-i/p 1010017 xxxxxxxxxx 44-lead qfn xxxxxxxxxx xxxxxxxxxx yywwnnn 18f45k80 example -i/ml 1010017 44-lead tqfp xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx yywwnnn example 18f45k80 -i/pt 1010017 3 e 3 e 3 e 3 e 64-lead tqfp xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx yywwnnn example 18f65k80 -i/pt 1010017 3 e 64-lead qfn xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx yywwnnn example 18f65k80 -i/mr 1010017
? 2011 microchip technology inc. ds39977d-page 589 pic18f66k80 family 32.2 package details the following sections give the technical details of the packages. 
       
    !! "# $%& ' ( ) !! *+  + (   ,   ! " #$ %! &  '(!%&! %(  % ")%%  % "     *   )  ! % " + &    "%   
,-. /01 / &    %  # % !  ))%!%%    ,21  $   &  '! ! )%!%%   '$$& %
!
   , 2% & %! %
* " ) '
  % 
 *  
$ % % " % %%
133)))&
&3
*  4% 55,, &  5&% 6 67 8 6!&( $ 6 9 % :./0 7  ;  %  9   % "$$    . 0% %* + ,2 7  <"% , :/0 ,#
 " "<"% , +:. +  7  5  %  :/0 ,#
 " "5  %  +:. +  0% %<"% ( + +9 + 0% %5  % 5 +  . 0% % % ,#
 " " =  > > d e 2 1 n e2 exposed pad 2 1 d2 n e b k l note 1 a3 a a1 top view bottom view 
    ) 0 /
pic18f66k80 family ds39977d-page 590 ? 2011 microchip technology inc. 
       
    !! "# $%& ' ( ) !! *+  + (  , 2% & %! %
* " ) '
  % 
 *  
$ % % " % %%
133)))&
&3
* 
? 2011 microchip technology inc. ds39977d-page 591 pic18f66k80 family 
  %! - + %-  . /0 !! "# $%-1*&   ,   ! " #$ %! &  '(!%&! %(  % ")%%  % "    ? $ %0  %  % + &    ","%!" &"$ 
%!  "$ 
%!    % # ".&&
 "   &    "%   
,-. /01 / &    %  # % !  ))%!%%    ,21  $   &  '! ! )%!%%   '$$& %
!
   , 2% & %! %
* " ) '
  % 
 *  
$ % % " % %%
133)))&
&3
*  4% 55,, &  5&% 6 67 8 6!&( $ 6 9 % /0 7  ;  %  > > :. " " * *  . > > % "$$?   > + 7  <"% , +/0 " " * <"% , ./0 7  5  %  /0 0 &$ @
% a  . > . 2%5  % 5  >  2%
% 5 ,2 2%  
b > 9b 5 "*  9 > ++ 5 "<"% ( + > . " $%  
.b > .b " $%  /%%& .b > .b c h h l l1 a2 a1 a note 1 12 3 b e e e1 d n 
    ) 0 ./
pic18f66k80 family ds39977d-page 592 ? 2011 microchip technology inc. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
? 2011 microchip technology inc. ds39977d-page 593 pic18f66k80 family  %++#
  2 1++ %
  3 ! "# $%
21
&   ,   ! " #$ %! &  '(!%&! %(  % ")%%  % "    ? $ %0  %  % + &    ","%!" &"$ 
%!  "$ 
%!    % # "c
 "   &    "%   
,-. /01 / &    %  # % !  ))%!%%     , 2% & %! %
* " ) '
  % 
 *  
$ % % " % %%
133)))&
&3
*  4% 60;, &  5&% 6 67 8 6!&( $ 6 9 % /0 
% %    > >  " " * *   +. . / % %    . > > !" %!" <"% ,  + ++. " " * <"% ,  9. . 7  5  %  +. +:.  
% %   5  + . 5 "*  9  . 4
5 "<"% (  .  5) 5 "<"% (  9  7  )
 ? / > > + note 1 n 12 d e1 eb c e l a2 e b b1 a1 a 3 
    ) 0 /
pic18f66k80 family ds39977d-page 594 ? 2011 microchip technology inc. 
  %(4+ %! - + %%  03 !! "# $%%-
&   ,   ! " #$ %! &  '(!%&! %(  % ")%%  % "    &    ","%!" &"$ 
%!  "$ 
%!    % # "&&
 "  + &    "%   
,-. /01 / &    %  # % !  ))%!%%    ,21  $   &  '! ! )%!%%   '$$& %
!
   , 2% & %! %
* " ) '
  % 
 *  
$ % % " % %%
133)))&
&3
*  4% 55,, &  5&% 6 67 8 6!&( $ 6 9 % :./0 7  ;  %  > >  " " * *  :. . 9. % "$$  . > > 7  <"% ,  9 9 " " * <"% , . .+ .: 7  5  %    . 2%5  % 5 .. . . 2%
% 5 .,2 5 "*   > . 2%  b b 9b 5 "<"% (  > +9 l l1 c a2 a1 a e e1 d n 1 2 note 1 b e 
    ) 0 +/
? 2011 microchip technology inc. ds39977d-page 595 pic18f66k80 family note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
pic18f66k80 family ds39977d-page 596 ? 2011 microchip technology inc. )
  2 1++ 
   ! "# $
21
&   ,   ! " #$ %! &  '(!%&! %(  % ")%%  % "    ? $ %0  %  % + &    ","%!" &"$ 
%!  "$ 
%!    % # "c
 "   &    "%   
,-. /01 / &    %  # % !  ))%!%%     , 2% & %! %
* " ) '
  % 
 *  
$ % % " % %%
133)))&
&3
*  4% 60;, &  5&% 6 67 8 6!&( $ 6  % /0 
% %    > > . " " * *  . > . / % %    . > > !" %!" <"% , . > :. " " * <"% , 9. > .9 7  5  %  9 > . 
% %   5 . >  5 "*  9 > . 4
5 "<"% ( + >  5) 5 "<"% (  > + 7  )
 ? / > >  n note 1 e1 d 123 a a1 b1 be c eb e l a2 
    ) 0 :/
? 2011 microchip technology inc. ds39977d-page 597 pic18f66k80 family ))
       
    !! "# $&   ,   ! " #$ %! &  '(!%&! %(  % ")%%  % "     *   )  ! % " + &    "%   
,-. /01 / &    %  # % !  ))%!%%    ,21  $   &  '! ! )%!%%   '$$& %
!
   , 2% & %! %
* " ) '
  % 
 *  
$ % % " % %%
133)))&
&3
*  4% 55,, &  5&% 6 67 8 6!&( $ 6  % :./0 7  ;  %  9   % "$$    . 0% %* + ,2 7  <"% , 9/0 ,#
 " "<"% , :+ :. :9 7  5  %  9/0 ,#
 " "5  %  :+ :. :9 0% %<"% ( . + +9 0% %5  % 5 +  . 0% % % ,#
 " " =  > > d exposed pad d2 e b k l e2 2 1 n note 1 2 1 e n bottom view top view a3 a1 a 
    ) 0 +/
pic18f66k80 family ds39977d-page 598 ? 2011 microchip technology inc. ))
       
    !! "# $&  , 2% & %! %
* " ) '
  % 
 *  
$ % % " % %%
133)))&
&3
* 
? 2011 microchip technology inc. ds39977d-page 599 pic18f66k80 family ))
  5(+    6 
5  777 !! "#  !! $5
&   ,   ! " #$ %! &  '(!%&! %(  % ")%%  % "    0 &$   %    
% d e &   + &    ","%!" &"$ 
%!  "$ 
%!    % # ".&&
 "   &    "%   
,-. /01 / &    %  # % !  ))%!%%    ,21  $   &  '! ! )%!%%   '$$& %
!
   , 2% & %! %
* " ) '
  % 
 *  
$ % % " % %%
133)))&
&3
*  4% 55,, &  5&% 6 67 8 6!&( $5 " 6  5 "% 9/0 7  ;  %  > >  " " * *  .  . % "$$  . > . 2%5  % 5 . : . 2%
% 5 ,2 2%  b +.b b 7  <"% , /0 7  5  %  /0 " " * <"% , /0 " " * 5  %  /0 5 "*   >  5 "<"% ( + + . " $%  
b b +b " $%  /%%& b b +b a e e1 d d1 e b note 1 note 2 n 123 c a1 l a2 l1 
    ) 0 :/
pic18f66k80 family ds39977d-page 600 ? 2011 microchip technology inc. ))
  5(+    6 
5  777 !! "#  !! $5
&  , 2% & %! %
* " ) '
  % 
 *  
$ % % " % %%
133)))&
&3
* 
? 2011 microchip technology inc. ds39977d-page 601 pic18f66k80 family note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
pic18f66k80 family ds39977d-page 602 ? 2011 microchip technology inc. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
? 2011 microchip technology inc. ds39977d-page 603 pic18f66k80 family note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
pic18f66k80 family ds39977d-page 604 ? 2011 microchip technology inc. )
  5(+    6 
5  777 !! "#  !! $5
&   ,   ! " #$ %! &  '(!%&! %(  % ")%%  % "    0 &$   %    
% d e &   + &    ","%!" &"$ 
%!  "$ 
%!    % # ".&&
 "   &    "%   
,-. /01 / &    %  # % !  ))%!%%    ,21  $   &  '! ! )%!%%   '$$& %
!
   , 2% & %! %
* " ) '
  % 
 *  
$ % % " % %%
133)))&
&3
*  4% 55,, &  5&% 6 67 8 6!&( $5 " 6 : 5 "% ./0 7  ;  %  > >  " " * *  .  . % "$$  . > . 2%5  % 5 . : . 2%
% 5 ,2 2%  b +.b b 7  <"% , /0 7  5  %  /0 " " * <"% , /0 " " * 5  %  /0 5 "*   >  5 "<"% (    " $%  
b b +b " $%  /%%& b b +b d d1 e e1 e b n note 1 123 note 2 c l a1 l1 a2 a 
    ) 0 9./
? 2011 microchip technology inc. ds39977d-page 605 pic18f66k80 family )
  5(+    6 
5  777 !! "#  !! $5
&  , 2% & %! %
* " ) '
  % 
 *  
$ % % " % %%
133)))&
&3
* 
pic18f66k80 family ds39977d-page 606 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds39977d-page 607 pic18f66k80 family appendix a: revision history revision a (august 2010) original data sheet for pic18f66k80 family devices. revision b (december 2010) changes to section 31.0 ?electrical characteristics? and minor text edits throughout document. revision c (january 2011) section 2.0 ?guidelines for getting started with pic18fxxkxx microcontrollers? was added to the data sheet. changes to section 31.0 ?electrical characteristics? for pic18f66k80 family devices. minor text edits throughout document. revision d (november 2011) preliminary conditions have been deleted from document. appendix b: migration to pic18f66k80 family devices in the pic18f66k80, pic18f4580, pic18f4680 and 18f8680 families are similar in their functions and features. code can be migrated from the other families to the pic18f66k80 without many changes. the differences between the device families are listed in table b-1 and ta bl e b - 2 . for more details on migrating to the pic18f66k80, refer to ?pic18fxx80 to pic18fxxk80 migration guide? (ds39982). table b-1: notable differences between 28, 40 and 44-pin devices ? pic18f66k80, pic18f4580 and pic18f4680 families characteristic pic18f66k80 family pic18f4680 family pic18f4580 family max operating frequency 64 mhz 40 mhz 40 mhz max program memory 64 kbytes 64 kbytes 32 kbytes data memory (bytes) 3,648 3,328 1,536 ctmu yes no no sosc oscillator options low-power oscillator option for sosc no options no options t1cki clock t1cki can be used as a clock without enabling the sosc oscillator no no intosc up to 16 mhz up to 8 mhz up to 8 mhz timers two 8-bit, three 16-bit one 8-bit, three 16-bit one 8-bit, three 16-bit eccp one for all devices 40 and 44-pin devices ? one 28-pin devices ? none 40 and 44-pin devices ? one 28-pin devices ? none ccp four one one data eeprom (bytes) 1,024 1,024 256 wdt prescale options 22 16 16 5v operation 18fxxk80 parts ? 5v operation 18lfxxk80 parts ? 3.3v operation ye s yes nanowatt xlp yes no no regulator 18fxxk80 parts ? yes 18lfxxk80 parts ? no no no low-power bor yes no no a/d converter 12-bit signed differential 10-bit 10-bit a/d channels 28-pin devices ? 8 channels 40 and 44-pin devices ? 15 channels 8 channels for 28-pin devices/ 11 channels for 40 and 44-pin devices 8 channels for 28-pin devices/ 11 channels for 40 and 44-pin devices internal temp sensor yes no no eusart two one one comparators two 28-pin devices ? none 40 and 44-pin devices ? two 28-pin devices ? none 40 and 44-pin devices ? two oscillator options 14 nine nine ultra low-power wake-up (ulpw) ye s n o no adjustable slew rate for i/o yes no no pll available for all oscillator options available only for high-speed crystal and internal oscillator available only for high-speed crystal and internal oscillator txm modulator no no no
pic18f66k80 family ds39977d-page 608 ? 2011 microchip technology inc. table b-2: notable differences between 64-pin devices ? pic18f66k80 and pic18f8680 families characteristic pic18f66k80 family pic18f8680 family max operating frequency 64 mhz 40 mhz max program memory 64k 64k data memory (bytes) 3,648 3,328 ctmu yes no sosc oscillator options low-power oscillator option for sosc no options t1cki clock t1cki can be used as a clock without enabling the sosc oscillator no intosc up to 16 mhz no internal oscillator spi/i 2 c? 1 module 1 module timers two 8-bit, three 16-bit two 8-bit, three 16-bit eccp 1 1 ccp 4 1 data eeprom (bytes) 1,024 1,024 wdt prescale options 22 16 5v operation 18fxxk80 parts ? 5v operation 18lfxxk80 parts ? 3.3v operation yes nanowatt xlp yes no on-chip 3.3v regulator 18fxxk80 parts ? yes 18lfxxk80 parts ? no no low-power bor yes no a/d converter 12-bit signed differential 10-bit a/d channels 15 channels 12 channels internal temp sensor yes no eusart two one comparators two two oscillator options 14 seven ultra low-power wake-up (ulpw) yes no adjustable slew rate for i/o yes no pll available for all oscillator options available for only high-speed crystal and external oscillator data signal modulator yes no
? 2011 microchip technology inc. ds39977d-page 609 pic18f66k80 family index a a/d .................................................................................... 363 a/d converter interrupt, configuring ........................ 371 acquisition requirements ......................................... 372 adresh register..................................................... 369 analog port pins, configuring................................... 373 associated registers ................................................ 376 automatic acquisition time....................................... 373 configuring the module............................................. 371 conversion clock (t ad ) ............................................ 373 conversion requirements ........................................ 588 conversion status (go/done bit) ........................... 369 conversions .............................................................. 374 converter characteristics ......................................... 587 differential converter ................................................ 363 operation in power-managed modes ....................... 375 use of the special event triggers ............................ 375 absolute maximum ratings .............................................. 541 ac (timing) characteristics .............................................. 568 load conditions for device timing specifications........................................ 569 parameter symbology .............................................. 568 temperature and voltage specifications .................. 569 timing conditions ..................................................... 569 ackstat ......................................................................... 328 ackstat status flag ...................................................... 328 adcon0 register go/done bit............................................................ 369 addfsr ........................................................................... 530 addlw ............................................................................. 493 addulnk......................................................................... 530 addwf ............................................................................. 493 addwfc .......................................................................... 494 adresl register ............................................................. 369 analog-to-digital converter. see a/d. andlw ............................................................................. 494 andwf ............................................................................. 495 assembler mpasm assembler................................................... 538 auto-wake-up on sync break character .......................... 354 b baud rate generator ........................................................ 324 bc ..................................................................................... 495 bcf ................................................................................... 496 bf ..................................................................................... 328 bf status flag .................................................................. 328 bit timing configuration registers brgcon1 ................................................................ 456 brgcon2 ................................................................ 456 brgcon3 ................................................................ 456 block diagrams a/d ............................................................................ 370 analog input model ................................................... 371 baud rate generator................................................ 324 can buffers and protocol engine............................. 396 capture mode operation .................................. 263, 275 comparator analog input model ............................... 380 comparator configurations....................................... 382 comparator module .................................................. 377 comparator voltage reference ................................ 386 comparator voltage reference output buffer.......... 387 compare mode operation ................................ 266, 276 connections for on-chip voltage regulator ............ 478 crystal/ceramic resonator operation (hs, hspll........................................................ 60 ctmu ....................................................................... 241 ctmu current source calibration circuit ................ 247 ctmu temperature measurement circuit ............... 255 ctmu typical connections and internal configuration for pulse delay generation ........ 256 ctmu typical connections and internal configuration for time measurement ............... 254 data signal modulator .............................................. 202 device clock............................................................... 54 differential channel measurement ........................... 363 eusart receive ..................................................... 352 eusart transmit .................................................... 349 external components for the sosc oscillator......... 220 external power-on reset circuit (slow v dd power-up) ......................................... 83 fail-safe clock monitor (fscm)............................... 481 full-bridge application.............................................. 281 generic i/o port operation....................................... 177 half-bridge applications ................................... 280, 287 high/low-voltage detect with external input ........... 390 interrupt logic........................................................... 154 intio1 oscillator mode .............................................. 62 intio2 oscillator mode .............................................. 62 mssp (i 2 c master mode)......................................... 322 mssp (i 2 c mode)..................................................... 302 mssp (spi mode) .................................................... 293 on-chip reset circuit................................................. 81 pic18f2xk80............................................................. 17 pic18f4xk80............................................................. 18 pic18f6xk80............................................................. 19 pll ............................................................................. 61 portd and porte (parallel slave port)................ 198 pwm (enhanced mode) ........................................... 277 pwm operation (simplified) ..................................... 268 rc oscillator mode .................................................... 59 rcio oscillator mode................ ................................. 59 reads from flash program memory ........................ 139 simplified steering.................................................... 290 single channel measurement .................................. 363 single comparator.................................................... 380 table read operation .............................................. 135 table write operation .............................................. 136 table writes to flash program memory ................... 141 timer0 in 16-bit mode .............................................. 212 timer0 in 8-bit mode ................................................ 212 timer1 ...................................................................... 219 timer2 ...................................................................... 228 timer3 ...................................................................... 232 timer4 ...................................................................... 240 transmit buffers ....................................................... 446 ultra low-power wake-up initialization...................... 79 using open-drain output ......................................... 179 watchdog timer ....................................................... 476 bn..................................................................................... 496 bnc .................................................................................. 497 bnn .................................................................................. 497 bnov ............................................................................... 498 bnz .................................................................................. 498 bor. see brown-out reset. bov .................................................................................. 501
pic18f66k80 family ds39977d-page 610 ? 2011 microchip technology inc. bra................................................................................... 499 break character (12-bit) transmit and receive ............... 356 brg. see baud rate generator. brown-out reset (bor) ...................................................... 84 detecting..................................................................... 84 disabling in sleep mode ............................................. 84 software enabled........................................................ 84 bsf ................................................................................... 499 btfsc .............................................................................. 500 btfss............................................................................... 500 btg................................................................................... 501 bz...................................................................................... 502 c c compilers mplab c18 .............................................................. 538 call ................................................................................. 502 callw.............................................................................. 531 can module external-internal clock in hs-pll based oscillators .............................................. 451 capture (ccp module)...................................................... 263 ccp pin configuration.............................................. 263 ccprxh:ccprxl registers .................................... 263 software interrupt ..................................................... 264 timer1/3 mode selection .......................................... 263 capture (eccp module) ................................................... 274 ccpr1h:ccpr1l registers.................................... 274 eccp pin configuration ........................................... 274 prescaler................................................................... 275 software interrupt ..................................................... 275 timer1/2/3/4 mode selection .................................... 275 capture, compare, timer1/3 associated registers ................................................ 267 capture/compare/pwm (ccp)......................................... 259 capture mode. see capture. ccp mode and timer resources ............................. 262 ccprxh register ..................................................... 262 ccprxl register...................................................... 262 compare mode. see compare. configuration............................................................. 262 open-drain output option ........................................ 262 charge time measurement unit (ctmu) ......................... 241 associated registers ................................................ 258 calibrating the module .............................................. 246 creating a delay ....................................................... 256 effects of a reset...................................................... 258 measuring capacitance ............................................ 252 measuring time ........................................................ 254 module initialization .................................................. 246 operation .................................................................. 245 during sleep, idle modes.................................. 258 temperature measurement ...................................... 255 clock sources ..................................................................... 58 default system clock on reset .................................. 59 selection using osccon register ............................ 58 clrf................................................................................. 503 clrwdt........................................................................... 503 code examples 16 x 16 signed multiply routine ............................... 152 16 x 16 unsigned multiply routine ........................... 152 8 x 8 signed multiply routine ................................... 151 8 x 8 unsigned multiply routine ............................... 151 capacitance calibration routine .............................. 251 changing between capture prescalers ............ 264, 275 changing to configuration mode .............................. 400 computed goto using an offset value.................. 109 current calibration routine ...................................... 249 data eeprom read................................................ 148 data eeprom refresh routine............................... 149 data eeprom write ................................................ 148 erasing a flash program memory row.................... 140 fast register stack .................................................. 109 how to clear ram (bank 1) using indirect addressing........................................... 128 initializing porta..................................................... 181 initializing portb..................................................... 184 initializing portc .................................................... 187 initializing portd .................................................... 190 initializing porte..................................................... 193 initializing portf..................................................... 195 initializing portg .................................................... 196 loading the sspbuf (sspsr) register.................. 296 reading a can message ......................................... 416 reading a flash program memory word ................. 139 routine for capacitive touch switch........................ 253 routine for temperature measurement using internal diode ................................. 255, 257 saving status, wreg and bsr registers in ram.............................................. 175 setup for ctmu calibration routines ...................... 248 transmitting a can message using banked method ................................................ 408 transmitting a can message using win bits.......... 409 ultra low-power wake-up initialization ...................... 79 win and icode bits usage in interrupt service routine to access tx/rx buffers..................... 400 writing to flash program memory .................... 142?143 code protection ................................................................ 461 comf ............................................................................... 504 comparator....................................................................... 377 analog input connection considerations ................. 380 associated registers ................................................ 384 configuration ............................................................ 381 control ...................................................................... 381 effects of a reset ..................................................... 384 enable and input selection....................................... 381 enable and output selection .................................... 381 interrupts .................................................................. 383 operation .................................................................. 380 operation during sleep ............................................ 384 response time......................................................... 380 comparator specifications................................................ 567 comparator voltage reference ........................................ 385 accuracy and error ................................................... 386 associated registers ................................................ 387 configuring ............................................................... 385 connection considerations....................................... 386 effects of a reset ..................................................... 386 operation during sleep ............................................ 386 compare (ccp module) ................................................... 265 ccp pin configuration.............................................. 265 software interrupt ..................................................... 265 special event trigger ............................................... 265 timer1/3 mode selection.......................................... 265 compare (eccp module)................................................. 276 ccpr1 register ....................................................... 276 pin configuration ...................................................... 276 software interrupt ..................................................... 276 special event trigger ....................................... 238, 276 timer1/2/3/4 mode selection.................................... 276
? 2011 microchip technology inc. ds39977d-page 611 pic18f66k80 family computed goto.............................................................. 109 configuration bits.............................................................. 461 configuration mismatch (cm) reset ................................... 85 configuration mode........................................................... 442 configuration register protection ..................................... 486 core features easy migration ............................................................ 14 extended instruction set............................................. 13 memory options.......................................................... 13 nanowatt technology ................................................. 13 oscillator options and features ................................. 13 cpfseq ........................................................................... 504 cpfsgt ........................................................................... 505 cpfslt ............................................................................ 505 crystal oscillator/ceramic resonator ................................. 60 customer change notification service ............................. 623 customer notification service........................................... 623 customer support............................................................. 623 d data addressing modes.................................................... 128 comparing addressing modes with the extended instruction set enabled .................... 133 direct......................................................................... 128 indexed literal offset................................................ 132 bsr .................................................................. 134 instructions affected ......................................... 132 mapping access bank ...................................... 134 indirect ...................................................................... 128 inherent and literal ................................................... 128 data eeprom associated registers ................................................ 150 code protection ........................................................ 486 during code-protect ................................................. 149 eeadr and eeadrh registers .............................. 145 eecon1 and eecon2 registers ............................ 145 overview ................................................................... 145 reading..................................................................... 147 spurious write protection ......................................... 149 using......................................................................... 149 write verify ............................................................... 147 writing....................................................................... 147 data eeprom memory operation during code-protect ................................ 149 data memory .................................................................... 112 access bank ............................................................. 114 bank select register (bsr)...................................... 112 extended instruction set........................................... 132 general purpose registers....................................... 114 memory maps pic18fx5k80/x6k80 devices ......................... 113 special function registers ............................... 115 special function registers ....................................... 115 data signal modulator (dsm) ........................................... 201 associated registers ................................................ 210 carrier signal sources.............................................. 203 carrier source pin disable........................................................ 206 polarity select ................................................... 206 carrier synchronization ............................................ 203 effects of a reset...................................................... 206 modulated output polarity ........................................ 206 modulator signal sources......................................... 203 modulator source pin disable .................................. 206 operation .................................................................. 203 operation in sleep mode .......................................... 206 programmable modulator data ................................ 206 slew rate control..................................................... 206 daw ................................................................................. 506 dc characteristics............................................................ 564 ctmu current source specifications....................... 565 power-down and supply current ............................. 544 supply voltage ......................................................... 543 dcfsnz ........................................................................... 507 decf ................................................................................ 506 decfsz ........................................................................... 507 default system clock ......................................................... 59 details on individual family members ................................ 14 development support ....................................................... 537 device overview................................................................. 13 features (28-pin devices).......................................... 15 features (40/44-pin devices)..................................... 15 features (64-pin devices).......................................... 16 device reset timers .......................................................... 85 oscillator start-up timer (ost)... ............................... 85 pll lock time-out ..................................................... 85 power-up timer (pwrt) ............................................ 85 direct addressing ............................................................. 129 disable/sleep mode.......................................................... 442 e ecan module ................................................................... 395 baud rate setting .................................................... 450 bit time partitioning ................................................. 450 bit timing configuration registers ........................... 456 calculating t q , nominal bit rate and nominal bit time .............................................. 453 can baud rate registers........................................ 434 can control and status registers ........................... 397 can i/o control register ......................................... 437 can interrupt registers ........................................... 438 can interrupts.......................................................... 457 bus activity wake-up........................................ 458 bus-off ............................................................. 459 code bits .......................................................... 458 error ................................................................. 458 message error .................................................. 458 receive ............................................................ 458 receiver bus passive....................................... 459 receiver overflow ............................................ 459 receiver warning ............................................. 459 transmit............................................................ 458 transmitter bus passive................................... 459 transmitter warning ......................................... 459 can message buffers .............................................. 444 dedicated receive ........................................... 444 dedicated transmit .......................................... 444 programmable auto-rtr ................................. 445 programmable transmit/receive ..................... 444 can message transmission .................................... 445 aborting ............................................................ 445 initiating ............................................................ 445 priority .............................................................. 446 can modes of operation ......................................... 442 can registers.......................................................... 397 configuration mode .................................................. 442 dedicated can receive buffer registers ................ 410 dedicated can transmit buffer registers ............... 404 disable/sleep mode ................................................. 442
pic18f66k80 family ds39977d-page 612 ? 2011 microchip technology inc. error detection.......................................................... 456 acknowledge..................................................... 456 bit...................................................................... 456 crc .................................................................. 456 error modes and counters................................ 456 error states....................................................... 456 form.................................................................. 456 stuff bit ............................................................. 456 error modes state (diagram) .................................... 457 error recognition mode ............................................ 443 filter-mask truth (table)............................................ 448 functional modes...................................................... 443 mode 0 (legacy mode) ..................................... 443 mode 1 (enhanced legacy mode).................... 443 mode 2 (enhanced fifo mode) ....................... 444 information processing time (ipt) ........................... 453 lengthening a bit period........................................... 454 listen only mode ...................................................... 443 loopback mode ........................................................ 443 message acceptance filters and masks .......... 425, 448 message acceptance mask and filter operation .......................................................... 449 message reception .................................................. 447 enhanced fifo mode....................................... 448 priority............................................................... 447 time-stamping.................................................. 448 normal mode ............................................................ 442 oscillator tolerance ...... ....................... ............ ......... 455 overview ................................................................... 395 phase buffer segments ............................................ 453 programmable tx/rx and auto-rtr buffers .......... 417 programming time segments .................................. 455 propagation segment ............................................... 453 sample point............................................................. 453 shortening a bit period ............................................. 455 synchronization ........................................................ 454 hard .................................................................. 454 resynchronization ............................................ 454 rules................................................................. 454 synchronization segment ......................................... 453 time quanta ............................................................. 453 values for icode (table) .......................................... 458 effect on standard pic18 instructions .............................. 534 effects of power-managed modes on various clock sources............................................................. 65 electrical characteristics................................................... 541 enhanced capture/compare/pwm (eccp) ..................... 271 capture mode. see capture. compare mode. see compare. eccp mode and timer resources........................... 274 enhanced pwm mode .............................................. 277 auto-restart...................................................... 286 auto-shutdown ................................................. 284 direction change in full-bridge output mode ............................................. 283 full-bridge application ...................................... 281 full-bridge mode............................................... 281 half-bridge application ..................................... 280 half-bridge application examples..................... 287 half-bridge mode .............................................. 280 output relationships (active-high and active-low) ............................................... 278 output relationships diagram .......................... 279 programmable dead-band delay ..................... 287 shoot-through current..................................... 287 start-up considerations.................................... 284 outputs and configuration........................................ 274 enhanced capture/compare/pwm (eccp) and timer1/2/3/4 associated registers........................... 292 enhanced universal synchronous asynchronous receiver transmitter (eusart). see eusart. equations 16 x 16 signed multiplication algorithm.................... 152 16 x 16 unsigned multiplication algorithm................ 152 a/d acquisition time ................................................ 372 a/d minimum charging time.................................... 372 calculating the minimum required acquisition time ............................................... 372 errata .................................................................................. 11 error recognition mode.................................................... 442 eusart asynchronous mode ................................................. 349 12-bit break transmit and receive.................. 356 associated registers, receive......................... 353 associated registers, transmit........................ 351 auto-wake-up on sync break .......................... 354 receiver ........................................................... 352 setting up 9-bit mode with address detect ......................................... 352 transmitter ....................................................... 349 baud rate generator operation in power-managed mode................. 343 baud rate generator (brg) .................................... 343 associated registers........................................ 344 auto-baud rate detect..................................... 347 baud rate error, calculating............................ 344 baud rates, asynchronous modes .................. 345 high baud rate select (brgh bit) .................. 343 sampling........................................................... 343 synchronous master mode....................................... 357 associated registers, receive......................... 360 associated registers, transmit........................ 358 reception ......................................................... 359 transmission .................................................... 357 synchronous slave mode......................................... 361 associated registers, receive......................... 362 associated registers, transmit........................ 361 reception ......................................................... 362 transmission .................................................... 361 extended instruction set addfsr................................................................... 530 addulnk................................................................. 530 callw ..................................................................... 531 movsf ..................................................................... 531 movss..................................................................... 532 pushl...................................................................... 532 subfsr ................................................................... 533 subulnk................................................................. 533 external oscillator modes clock input (ec modes).............................................. 61 hs............................................................................... 60
? 2011 microchip technology inc. ds39977d-page 613 pic18f66k80 family f fail-safe clock monitor............................................. 461, 481 exiting operation ...................................................... 481 interrupts in power-managed modes........................ 482 por or wake from sleep ......................................... 482 wdt during oscillator failure .................................. 481 fast register stack........................................................... 109 firmware instructions........................................................ 487 flash program memory .................................................... 135 associated registers ................................................ 143 control registers ...................................................... 136 eecon1 and eecon2 .................................... 136 tablat (table latch) register........................ 138 tblptr (table pointer) register..................... 138 erase sequence ....................................................... 140 erasing...................................................................... 140 operation during code-protect ................................ 143 reading..................................................................... 139 table pointer boundaries based on operation....................... 138 table pointer boundaries ......................................... 138 table reads and table writes ................................. 135 write sequence ........................................................ 141 writing....................................................................... 141 protection against spurious writes .................. 143 unexpected termination................................... 143 write verify ....................................................... 143 fscm. see fail-safe clock monitor. g goto ............................................................................... 508 h hardware multiplier ........................................................... 151 8 x 8 multiplication algorithms .................................. 151 operation .................................................................. 151 performance comparison (table).............................. 151 high/low-voltage detect .................................................. 389 applications............................................................... 393 associated registers ................................................ 394 current consumption................................................ 391 effects of a reset...................................................... 394 operation .................................................................. 390 during sleep ..................................................... 394 setup......................................................................... 391 start-up time ............................................................ 391 typical application .................................................... 393 hlvd. see high/low-voltage detect. .............................. 389 i i/o descriptions pic18f2xk80 ............................................................. 20 pic18f4xk80 ............................................................. 26 pic18f6xk80 ............................................................. 35 i/o ports ............................................................................ 177 analog, digital ports ................................................. 180 open-drain outputs.................................................. 179 output pin drive........................................................ 177 pin capabilities ......................................................... 177 port slew rate .......................................................... 180 pull-up configuration ................................................ 177 i 2 c mode (mssp) acknowledge sequence timing................................ 331 associated registers ................................................ 337 baud rate generator................................................ 324 bus collision during a repeated start condition................... 335 during a stop condition ................................... 336 clock arbitration ....................................................... 325 clock stretching ....................................................... 317 10-bit slave receive mode (sen = 1) ............. 317 10-bit slave transmit mode ............................. 317 7-bit slave receive mode (sen = 1) ............... 317 7-bit slave transmit mode ............................... 317 clock synchronization and the ckp bit.................... 318 effects of a reset ..................................................... 332 general call address support.................................. 321 i 2 c clock rate w/brg ............................................. 324 master mode............................................................. 322 operation.......................................................... 323 reception ......................................................... 328 repeated start condition timing ..................... 327 start condition timing ...................................... 326 transmission .................................................... 328 multi-master communication, bus collision and arbitration .................................................. 332 multi-master mode.................................................... 332 operation.................................................................. 307 read/write bit information (r/w bit)................ 307, 310 registers .................................................................. 302 serial clock (rc3refo//scl/sck) ........................ 310 slave mode............................................................... 307 address masking modes 5-bit .......................................................... 308 7-bit .......................................................... 309 addressing ....................................................... 307 reception ......................................................... 310 transmission .................................................... 310 sleep operation........................................................ 332 stop condition timing .............................................. 331 id locations.............................................................. 461, 486 idle modes .......................................................................... 72 incf ................................................................................. 508 incfsz............................................................................. 509 in-circuit debugger........................................................... 486 in-circuit serial programming (icsp)....................... 461, 486 indexed literal offset addressing and standard pic18 instructions.............................. 534 indexed literal offset mode.............................................. 534 indirect addressing ........................................................... 129 infsnz............................................................................. 509 initialization conditions for all registers ............................. 90 instruction cycle ............................................................... 110 clocking scheme...................................................... 110 flow/pipelining ......................................................... 110 instruction set................................................................... 487 addlw..................................................................... 493 addwf .................................................................... 493 addwf (indexed literal offset mode) ..................... 535 addwfc.................................................................. 494 andlw..................................................................... 494 andwf .................................................................... 495 bc............................................................................. 495 bcf .......................................................................... 496 bn............................................................................. 496 bnc .......................................................................... 497 bnn .......................................................................... 497 bnov ....................................................................... 498 bnz .......................................................................... 498 bov .......................................................................... 501
pic18f66k80 family ds39977d-page 614 ? 2011 microchip technology inc. bra........................................................................... 499 bsf ........................................................................... 499 bsf (indexed literal offset mode) ........................... 535 btfsc ...................................................................... 500 btfss ...................................................................... 500 btg........................................................................... 501 bz ............................................................................. 502 call ......................................................................... 502 clrf......................................................................... 503 clrwdt................................................................... 503 comf ....................................................................... 504 cpfseq ................................................................... 504 cpfsgt ................................................................... 505 cpfslt .................................................................... 505 daw.......................................................................... 506 dcfsnz ................................................................... 507 decf ........................................................................ 506 decfsz.................................................................... 507 extended instructions ............................................... 529 considerations when enabling ......................... 534 syntax ............................................................... 529 use with mplab ide tools .............................. 536 general format......................................................... 489 goto ....................................................................... 508 incf.......................................................................... 508 incfsz ..................................................................... 509 infsnz ..................................................................... 509 iorlw ...................................................................... 510 iorwf ...................................................................... 510 lfsr......................................................................... 511 movf........................................................................ 511 movff ..................................................................... 512 movlb ..................................................................... 512 movlw .................................................................... 513 movwf .................................................................... 513 mullw ..................................................................... 514 mulwf ..................................................................... 514 negf ........................................................................ 515 nop .......................................................................... 515 opcode field descriptions ........................................ 488 pop .......................................................................... 516 push ........................................................................ 516 rcall ...................................................................... 517 reset ...................................................................... 517 retfie ..................................................................... 518 retlw ..................................................................... 518 return ................................................................... 519 rlcf......................................................................... 519 rlncf ...................................................................... 520 rrcf ........................................................................ 520 rrncf ..................................................................... 521 setf ......................................................................... 521 setf (indexed literal offset mode) ......................... 535 sleep ...................................................................... 522 standard instructions ................................................ 487 subfwb................................................................... 522 sublw ..................................................................... 523 subwf ..................................................................... 523 subwfb................................................................... 524 swapf ..................................................................... 524 tblrd ...................................................................... 525 tblwt ...................................................................... 526 tstfsz .................................................................... 527 xorlw..................................................................... 527 xorwf..................................................................... 528 intcon register rbif bit .................................................................... 184 inter-integrated circuit. see i 2 c. internal oscillator block ...................................................... 62 adjustment.................................................................. 63 intio modes .............................................................. 62 intosc frequency drift............................................. 63 intosc output frequency ........................................ 63 intpll modes............................................................ 62 internal rc oscillator use with wdt........................................................... 476 internal voltage regulator specifications......................... 567 internet address ............................................................... 623 interrupt sources .............................................................. 461 a/d conversion complete ........................................ 371 capture complete (ccp).......................................... 264 capture complete (eccp) ....................................... 275 compare complete (ccp)........................................ 265 compare complete (eccp) ..................................... 276 ecan module ........................................................... 457 interrupt-on-change (rb7:rb4) ............................... 184 tmr0 overflow......................................................... 213 tmr1 overflow......................................................... 221 tmr2 to pr2 match (pwm) ..................................... 268 tmr3 overflow......................................................... 229 tmrx overflow ......................................................... 238 interrupts........................................................................... 153 associated registers ................................................ 175 during, context saving............................................. 175 intx pin .................................................................... 174 portb, interrupt-on-change ................................... 174 tmr0 ........................................................................ 174 interrupts, flag bits interrupt-on-change (rb7:rb4) flag (rbif bit) ...... 184 intosc. see internal oscillator block. iorlw .............................................................................. 510 iorwf.............................................................................. 510 l lfsr................................................................................. 511 listen only mode.............................................................. 442 loopback mode ................................................................ 442 m master clear reset (mclr ) ............................................... 83 master synchronous serial port (mssp). see mssp. memory organization ....................................................... 105 data memory ............................................................ 112 program memory ...................................................... 105 memory programming requirements............................... 566 microchip internet web site.............................................. 623 migration to pic18f66k80 ............................................... 609 movf ............................................................................... 511 movff ............................................................................. 512 movlb ............................................................................. 512 movlw ............................................................................ 513 movsf ............................................................................. 531 movss............................................................................. 532 movwf ............................................................................ 513 mplab asm30 assembler, linker, librarian ................... 538 mplab integrated development environment software ................................................................... 537 mplab pm3 device programmer .................................... 540 mplab real ice in-circuit emulator system ................ 539 mplink object linker/mplib object librarian ................ 538
? 2011 microchip technology inc. ds39977d-page 615 pic18f66k80 family mssp ack pulse......................................................... 307, 310 i 2 c mode. see i 2 c mode. module overview ...................................................... 293 spi master/slave connection ................................... 297 mullw ............................................................................. 514 mulwf ............................................................................. 514 n negf ................................................................................ 515 nop .................................................................................. 515 normal operation mode.................................................... 442 notable differences between pic18f66k80 and pic18f4580 and pic18f4680 families - 28, 40/44-pin devices............................... 609 notable differences between pic18f66k80 and pic18f8680 families - 64-pin devices .................... 610 o on-chip voltage regulator ............................................... 478 oscillator configuration................. ...................................... 53 ec ............................................................................... 53 ecio ........................................................................... 53 hs ............................................................................... 53 internal oscillator block .............................................. 62 intio1 ........................................................................ 53 intio2 ........................................................................ 53 lp................................................................................ 53 rc............................................................................... 53 rcio ........................................................................... 53 xt ............................................................................... 53 oscillator selection ....... ........................... ............... ...... .... 461 oscillator start-up timer (ost) .................................... 65, 86 oscillator switching..................... ........................................ 58 oscillator transitions .................... ...................................... 59 oscillator, timer1...................... ..................... ........... ........ 215 oscillator, timer3...................... ..................... ........... ........ 229 p p1a/p1b/p1c/p1d. see enhanced capture/compare/pwm (eccp). ............................. 277 packaging ......................................................................... 589 details ....................................................................... 591 marking ..................................................................... 589 parallel slave port (psp).................................................. 198 associated registers ................................................ 200 portd ..................................................................... 198 pin functions m clr /re3.................................................................. 26 av dd ........................................................................... 45 av ss ........................................................................... 45 mclr /re3............................................................ 20, 35 osc1/clkin/ra7........................................... 20, 26, 35 osc2/clkout/ra6....................................... 20, 26, 35 ra0/cv ref /an0/ulpwu ............................... 21, 27, 36 ra1/an1 ..................................................................... 21 ra1/an1/c1inc ................................................... 27, 36 ra2/ ref -/an2 ............................................................. 21 ra2/v ref -/an2//c2inc........................................ 36, 27 ra3/v ref +/an3.............................................. 21, 27, 36 ra5/an4/c2inb/hlvdin/t1cki/ss /ctmui.............. 21 ra5/an4/hlvdin/t1cki/ss ................................ 36, 27 rb0/an10/c1ina/flt0/int0 ..................................... 22 rb0/an10/flt0/int0........................................... 28, 37 rb1/an8/c1inb/p1b/ctdin/int1............................. 22 rb1/an8/ctdin/int1 .......................................... 28, 37 rb2/cantx/c1out/p1c/cted1/int2..................... 22 rb2/cantx/cted1/int2.................................... 28, 37 rb3/canrx/c2out/p1d/cted2/int3 .................... 22 rb3/canrx/cted2/int3 ................................... 28, 37 rb4/an9/c2ina/eccp1/p1a/ctpls/kbi0............... 23 rb4/an9/ctpls/kbi0 ......................................... 28, 37 rb5/t0cki/t3cki/ccp5/kbi1....................... 23, 28, 37 rb6/pgc/kbi2 ..................................................... 29, 38 rb6/pgc/tx2/ck2/kbi2 ........................................... 23 rb7/pgd/t3g/kbi3 ............................................. 29, 38 rb7/pgd/t3g/rx2/dt2/kbi3 ................................... 23 rc0/sosco/sclki ....................................... 24, 30, 39 rc1/sosc ................................................................. 30 rc1/sosci .......................................................... 24, 39 rc2/t1g/ccp2.............................................. 24, 30, 39 rc3/refo/scl/sck ..................................... 24, 30, 39 rc4/sda/sdi ................................................. 24, 30, 39 rc5/sdo........................................................ 24, 30, 39 rc6/cantx/tx1/ck1/ccp3 ............................... 24, 30 rc6/ccp3.................................................................. 39 rc7/canrx/rx1/dt1/ccp4 .............................. 25, 31 rc7/ccp4.................................................................. 39 rd0/c1ina/psp0................................................. 32, 40 rd1/c1inb/psp1................................................. 32, 40 rd2/c2ina/psp2................................................. 32, 40 rd3/c2inb/ctmui/psp3 .................................... 32, 40 rd4/eccp1/p1a/psp4 ....................................... 32, 40 rd5/p1b/psp5 .................................................... 32, 40 rd6/p1c/psp6 .......................................................... 41 rd6/tx2/ck2/p1c/psp6........................................... 33 rd7/p1d/psp7 .......................................................... 41 rd7/rx2/dt2/p1d/psp7 .......................................... 33 re0/an5/rd ........................................................ 42, 33 re1/an6/c1out/wr .......................................... 42, 33 re2/an7/c2out/cs ........................................... 33, 42 re4/canrx ............................................................... 42 re5/cantx ............................................................... 42 re6/rx2/dt2............................................................. 42 re7/tx2/ck2 ............................................................. 42 rf0/mdmin................................................................ 43 rf1............................................................................. 43 rf2/mdcin1 .............................................................. 43 rf3............................................................................. 43 rf4/mdcin2 .............................................................. 43 rf5............................................................................. 43 rf6/mdout............................................................... 43 rf7............................................................................. 43 rg0/rx1/dt1 ............................................................ 44 rg1/cantx2 ............................................................. 44 rg2/t3cki ................................................................. 44 rg3/tx1/ck1............................................................. 44 rg4/t0cki ................................................................. 44 v dd ........................................................... 34, 45, 34, 45 v ddcore /v cap ............................................... 25, 34, 45 v ss ........................................................... 34, 45, 25, 45 pll frequency multiplier ................................................... 61 hspll and ecpll oscillator modes ......................... 61 use with hf-intosc ................................................. 61 pll lock time-out.............................................................. 86 pop .................................................................................. 516 por. see power-on reset.
pic18f66k80 family ds39977d-page 616 ? 2011 microchip technology inc. porta associated registers ................................................ 183 lata register........................................................... 181 porta register ....................................................... 181 trisa register ......................................................... 181 portb associated registers ................................................ 186 latb register........................................................... 184 portb register ....................................................... 184 rb7:rb4 interrupt-on-change flag (rbif bit) ......... 184 trisb register ......................................................... 184 portc associated registers ................................................ 189 latc register .......................................................... 187 portc register ....................................................... 187 rc3/refo/scl/sck pin ......................................... 310 trisc register......................................................... 187 portd associated registers ................................................ 192 latd register .......................................................... 190 portd register ....................................................... 190 trisd register......................................................... 190 porte associated registers ................................................ 194 late register........................................................... 193 porte register ....................................................... 193 re0/an5/rd pin....................................................... 198 re1/an6/c1out/wr pin......................................... 198 re2/an7/c2out/cs pin.......................................... 198 trise register ......................................................... 193 portf associated registers ................................................ 195 latf register........................................................... 195 portf register ....................................................... 195 trisf register ......................................................... 195 portg associated registers ................................................ 197 latg register .......................................................... 196 portg register....................................................... 196 trisg register......................................................... 196 power-managed modes ...................................................... 67 and eusart operation............................................ 343 and pwm operation ................................................. 291 and spi operation .................................................... 301 clock transitions and status indicators...................... 68 entering....................................................................... 67 exiting idle and sleep modes ..................................... 78 by interrupt.......................................................... 78 by reset.............................................................. 78 by wdt time-out................................................ 78 without a start-up delay..................................... 78 idle modes .................................................................. 72 pri_idle ............................................................ 73 rc_idle............................................................. 74 sec_idle........................................................... 73 multiple sleep commands .......................................... 68 run modes.................................................................. 68 pri_run ............................................................ 68 rc_run ............................................................. 69 sec_run........................................................... 68 selecting ..................................................................... 67 sleep mode ................................................................. 72 osc1 and osc2 pin states ............................... 65 summary (table) ......................................................... 67 power-on reset (por)....................................................... 83 oscillator start-up timer (ost) ... ............................... 86 power-up timer (pwrt) ............................................ 85 time-out sequence .................................................... 86 power-up delays ................................................................ 65 power-up timer (pwrt) .............................................. 65, 85 prescaler, capture............................................................ 264 prescaler, timer0 ............................................................. 213 prescaler, timer2 ............................................................. 269 pri_idle mode.................................................................. 73 pri_run mode .................................................................. 68 program counter .............................................................. 107 pcl, pch and pcu registers ................................. 107 pclath and pclatu registers ............................. 107 program memory code protection ........................................................ 484 extended instruction set .......................................... 131 hard memory vectors............................................... 106 instructions ............................................................... 111 two-word ......................................................... 111 interrupt vector ......................................................... 106 look-up tables ......................................................... 109 memory maps ........................................................... 105 hard vectors and configuration words............ 106 reset vector............................................................. 106 program verification and code protection ....................... 483 associated registers ................................................ 484 programming, device instructions.................................... 487 psp. see parallel slave port. pulse-width modulation. see pwm (ccp module). push................................................................................ 516 push and pop instructions............................................. 108 pushl.............................................................................. 532 pwm (ccp module) associated registers ................................................ 270 duty cycle ................................................................ 269 example frequencies/resolutions ........................... 269 period ....................................................................... 268 setup for pwm operation......................................... 269 tmr2 to pr2 match ................................................. 268 pwm (eccp module) effects of a reset ..................................................... 291 operation in power-managed modes ....................... 291 operation with fail-safe clock monitor .................... 291 pulse steering mode ................................................ 288 steering synchronization.......................................... 290 pwm mode. see enhanced capture/compare/pwm ...... 277 q q clock ............................................................................. 269 r ram. see data memory. rc_idle mode................................................................... 74 rc_run mode................................................................... 69 rcall .............................................................................. 517 rcon register bit status during initialization ..................................... 89 reader response............................................................. 624 receiver warning ............................................................. 459 reference clock output ..................................................... 63 register file...................................................................... 114 register file summary ............................................. 117?126
? 2011 microchip technology inc. ds39977d-page 617 pic18f66k80 family registers adcon0 (a/d control 0) .......................................... 364 adcon1 (a/d control 1) .......................................... 365 adcon2 (a/d control 2) .......................................... 366 adresh (a/d result high byte, left justified, adfm = 0) ........................................................ 367 adresh (a/d result high byte, right justified, adfm = 1) ........................................................ 368 adresl (a/d result low byte, left justified, adfm = 0) ........................................................ 368 adresl (a/d result low byte, right justified, adfm = 1) ........................................................ 368 ancon0 (a/d port configuration 0)......................... 369 ancon1 (a/d port configuration 1)......................... 369 baudconx (baud rate control) ............................. 342 bie0 (buffer interrupt enable 0)................................ 441 bncon (tx/rx buffer n control, receive mode).................................................. 417 bncon (tx/rx buffer n control, transmit mode)................................................. 418 bndlc (tx/rx buffer n data length code in receive mode) .................................... 423 bndlc (tx/rx buffer n data length code in transmit mode) ................................... 424 bndm (tx/rx buffer n data field byte m in receive mode) .............................................. 422 bndm (tx/rx buffer n data field byte m in transmit mode) ............................................. 422 bneidh (tx/rx buffer n extended identifier, high byte in receive mode) ............................. 421 bneidh (tx/rx buffer n extended identifier, high byte in transmit mode) ............................ 421 bneidl (tx/rx buffer n extended identifier, low byte in receive mode) ...................... 421, 422 bnsidh (tx/rx buffer n standard identifier, high byte in receive mode) ............................. 419 bnsidh (tx/rx buffer n standard identifier, high byte in transmit mode) ............................ 419 bnsidl (tx/rx buffer n standard identifier, low byte in receive mode) .............................. 420 brgcon1 (baud rate control 1) ............................ 434 brgcon2 (baud rate control 2) ............................ 435 brgcon3 (baud rate control 3) ............................ 436 bsel0 (buffer select 0)............................................ 424 cancon (can control)........................................... 398 canstat (can status) ........................................... 399 ccp1con (enhanced capture/compare/pwm1 control) ............................................................. 272 ccpprxl (ccpx period low byte).......................... 261 ccprxh (ccpx period high byte)........................... 261 ccptmrs (ccp timer select) ........................ 260, 273 ccpxcon (ccpx control, ccp2-ccp5)................. 259 ciocon (can i/o control) ...................................... 437 cmstat (comparator status).................................. 379 cmxcon (comparator control x)............................. 378 comstat (can communication status) ................ 403 config1h (configuration 1 high) ........................... 464 config1l (configuration 1 low)............................. 463 config2h (configuration 2 high) ........................... 466 config2l (configuration 2 low)............................. 465 config3h (configuration 3 high) ........................... 467 config4l (configuration 4 low)............................. 468 config5h (configuration 5 high) ........................... 470 config5l (configuration 5 low)............................. 469 config6h (configuration 6 high) ........................... 472 config6l (configuration 6 low) ............................ 471 config7h (configuration 7 high)........................... 474 config7l (configuration 7 low) ............................ 473 ctmuconh (ctmu control high).......................... 242 ctmuconl (ctmu control low) ........................... 243 ctmuicon (ctmu current control)....................... 244 cvrcon (comparator voltage reference control) ........................................... 385 devid1 (device id 1)............................................... 475 devid2 (device id 2)............................................... 475 ecancon (enhanced can control) ....................... 402 eccp1as (eccp1 auto-shutdown control) ........... 285 eccp1del (enhanced pwm control)..................... 288 eecon1 (data eeprom control 1)........................ 146 eecon1 (eeprom control 1) ................................ 137 hlvdcon (high/low-voltage detect control) ........ 389 intcon (interrupt control) ...................................... 155 intcon2 (interrupt control 2) ................................. 156 intcon3 (interrupt control 3) ................................. 157 iocb (interrupt-on-change portb control) ........... 174 ipr1 (peripheral interrupt priority 1) ........................ 168 ipr2 (peripheral interrupt priority 2) ........................ 169 ipr3 (peripheral interrupt priority 3) ........................ 170 ipr4 (peripheral interrupt priority 4) ........................ 171 ipr5 (peripheral interrupt priority 5) ................ 172, 440 mdcarh (modulation high carrier control)............ 209 mdcarl (modulation low carrier control) ............. 210 mdcon (modulation control register) .................... 207 mdsrc (modulation source control) ...................... 208 msel0 (mask select 0)............................................ 430 msel1 (mask select 1)............................................ 431 msel2 (mask select 2)............................................ 432 msel3 (mask select 3)............................................ 433 odcon (peripheral open-drain control) ................ 179 osccon (oscillator control)..................................... 55 osccon2 (oscillator control 2)........................ 56, 231 osctune (oscillator tuning).................................... 57 padcfg1 (pad configuration) ................................ 178 pie1 (peripheral interrupt enable 1) ........................ 163 pie2 (peripheral interrupt enable 2) ........................ 164 pie3 (peripheral interrupt enable 3) ........................ 165 pie4 (peripheral interrupt enable 4) ........................ 166 pie5 (peripheral interrupt enable 5) ................ 167, 439 pir1 (peripheral interrupt request (flag) 1)............ 158 pir2 (peripheral interrupt request (flag) 2)............ 159 pir3 (peripheral interrupt request (flag) 3)............ 160 pir4 (peripheral interrupt request (flag) 4)............ 161 pir5 (peripheral interrupt request (flag) 5)...................................... 162, 438 pmd0 (peripheral module disable 0) ......................... 77 pmd1 (peripheral module disable 1) ......................... 76 pmd2 (peripheral module disable 2) ......................... 75 pspcon (parallel slave port control)..................... 199 pstr1con (pulse steering control)....................... 289 rcon (reset control)........................................ 82, 173 rcstax (receive status and control) .................... 341 refocon (reference oscillator control) ................. 64 rxb0con (receive buffer 0 control)...................... 410 rxb1con (receive buffer 1 control)...................... 412 rxbndlc (receive buffer n data length code).................................................... 415 rxbndm (receive buffer n data field byte m) ....... 415 rxbneidh (receive buffer n extended identifier, high byte) ......................................... 414
pic18f66k80 family ds39977d-page 618 ? 2011 microchip technology inc. rxbneidl (receive buffer n extended identifier, low byte) .......................................... 414 rxbnsidh (receive buffer n standard identifier, high byte) ......................................... 413 rxbnsidl (receive buffer n standard identifier, low byte) .......................................... 414 rxerrcnt (receive error count) .......................... 416 rxfbconn (receive filter buffer control n) ........... 429 rxfconn (receive filter control n) ........................ 428 rxfneidh (receive acceptance filter n extended identifier, high byte) ......................... 426 rxfneidl (receive acceptance filter n extended identifier, low byte) .......................... 426 rxfnsidh (receive acceptance filter n standard identifier filter, high byte)................. 425 rxfnsidl (receive acceptance filter n standard identifier filter, low byte).................. 425 rxmneidh (receive acceptance mask n extended identifier mask, high byte)................ 427 rxmneidl (receive acceptance mask n extended identifier mask, low byte) ................ 427 rxmnsidh (receive acceptance mask n standard identifier mask, high byte) ................ 426 rxmnsidl (receive acceptance mask n standard identifier mask, low byte) ................. 427 sdflc (standard data bytes filter length count) ................................................... 428 slrcon (slew rate control)................................... 180 sspcon1 (mssp control 1, i 2 c mode) .................. 304 sspcon1 (mssp control 1, spi mode) .................. 295 sspcon2 (mssp control 2, i 2 c master mode) ...... 305 sspcon2 (mssp control 2, i 2 c slave mode) ........ 306 sspmsk (i 2 c slave address mask)......................... 306 sspstat (mssp status, i 2 c mode)........................ 303 sspstat (mssp status, spi mode) ....................... 294 status .................................................................... 127 stkptr (stack pointer) ........................................... 108 t0con (timer0 control)........................................... 211 t1con (timer1 control)........................................... 215 t1gcon (timer1 gate control) ............................... 217 t2con (timer2 control)........................................... 227 t3con (timer3 control)........................................... 229 t3gcon (timer3 gate control) ............................... 230 t4con (timer4 control)........................................... 239 txbie (transmit buffers interrupt enable) ............... 441 txbncon (transmit buffer n control) ..................... 404 txbndlc (transmit buffer n data length code)............................................ 407 txbndm (transmit buffer n data field byte m) ....... 406 txbneidh (transmit buffer n extended identifier, high byte) ......................................... 405 txbneidl (transmit buffer n extended identifier, low byte) .......................................... 406 txbnsidh (transmit buffer n standard identifier, high byte) ......................................... 405 txbnsidl (transmit buffer n standard identifier, low byte) .......................................... 405 txerrcnt (transmit error count).......................... 407 txstax (transmit status and control) .................... 340 wdtcon (watchdog timer control)........................ 477 wpub (weak pull-up portb enable) ..................... 178 reset.............................................................................. 517 resets......................................................................... 81, 461 brown-out reset (bor)............................................ 461 oscillator start-up timer (ost) ................................ 461 power-on reset (por)............................................. 461 power-up timer (pwrt) .......................................... 461 retfie ............................................................................. 518 retlw ............................................................................. 518 return........................................................................... 519 return address stack....................................................... 107 return stack pointer (stkptr) ....................................... 108 revision history................................................................ 609 rlcf ................................................................................ 519 rlncf.............................................................................. 520 rrcf................................................................................ 520 rrncf ............................................................................. 521 s sck .................................................................................. 293 sdi.................................................................................... 293 sdo .................................................................................. 293 sec_idle mode ................................................................ 73 sec_run mode................................................................. 68 selective peripheral module control .................................. 74 serial clock, sck ............................................................. 293 serial data in (sdi)........................................................... 293 serial data out (sdo) ...................................................... 293 serial peripheral interface. see spi mode. setf................................................................................. 521 shoot-through current..................................................... 287 slave select (ss ).............................................................. 293 sleep .............................................................................. 522 sleep mode......................................................................... 72 software simulator (mplab sim) .................................... 539 special event trigger. see compare (ccp module). special event trigger. see compare (eccp mode). spi mode (mssp) ............................................................ 293 associated registers ................................................ 301 bus mode compatibility ............................................ 301 effects of a reset ..................................................... 301 enabling spi i/o ....................................................... 297 master mode............................................................. 298 master/slave connection.......................................... 297 operation .................................................................. 296 operation in power-managed modes ....................... 301 serial clock............................................................... 293 serial data in ............................................................ 293 serial data out ......................................................... 293 slave mode............................................................... 299 slave select.............................................................. 293 slave select synchronization ................................... 299 spi clock .................................................................. 298 sspbuf register ..................................................... 298 sspsr register ....................................................... 298 typical connection ................................................... 297 .......................................................................................... 293 sspov ............................................................................. 328 sspov status flag .......................................................... 328 sspstat register r/w bit ............................................................. 307, 310 stack full/underflow resets............................................. 109
? 2011 microchip technology inc. ds39977d-page 619 pic18f66k80 family subfsr ........................................................................... 533 subfwb........................................................................... 522 sublw ............................................................................. 523 subulnk ......................................................................... 533 subwf ............................................................................. 523 subwfb........................................................................... 524 swapf ............................................................................. 524 t table pointer operations (table)....................................... 138 table reads/table writes ................................................ 109 tblrd .............................................................................. 525 tblwt .............................................................................. 526 time-out in various situations (table)................................. 86 timer0............................................................................... 211 associated registers ................................................ 213 operation .................................................................. 212 overflow interrupt ..................................................... 213 prescaler................................................................... 213 switching assignment....................................... 213 prescaler assignment (psa bit) ............................... 213 prescaler select (t0ps2:t0ps0 bits) ...................... 213 reads and writes in 16-bit mode ............................. 212 source edge select (t0se bit)................................. 212 source select (t0cs bit).......................................... 212 timer1............................................................................... 215 16-bit read/write mode............................................ 220 associated registers ................................................ 226 clock source selection............................................. 218 gate .......................................................................... 222 interrupt..................................................................... 221 operation .................................................................. 218 oscillator ............................. ..................... ........... ...... 215 oscillator, as secondary clock ................................... 58 resetting, using the eccp special event trigger .................................................... 222 sosc oscillator........................................................ 220 layout considerations ...................................... 221 use as a clock source ..................................... 221 tmr1h register ....................................................... 215 tmr1l register........................................................ 215 timer2............................................................................... 227 associated registers ................................................ 228 interrupt..................................................................... 228 operation .................................................................. 227 output ....................................................................... 228 pr2 register............................................................. 268 tmr2 to pr2 match interrupt ................................... 268 timer3............................................................................... 229 16-bit read/write mode............................................ 233 associated registers ................................................ 238 gates ........................................................................ 234 operation .................................................................. 232 oscillator ............................. ..................... ........... ...... 229 overflow interrupt ............................................. 229, 238 sosc oscillator use as the timer3 clock source ...................... 233 special event trigger (eccp) .................................. 238 tmr3h register ....................................................... 229 tmr3l register........................................................ 229 timer4 .............................................................................. 239 associated registers................................................ 240 interrupt .................................................................... 240 operation.................................................................. 239 output....................................................................... 240 postscaler. see postscaler, timer4. pr4 register ............................................................ 239 prescaler. see prescaler, timer4. tmr4 register ......................................................... 239 timing diagrams a/d conversion ........................................................ 588 asynchronous reception.......................................... 353 asynchronous transmission .................................... 350 asynchronous transmission (back-to-back)............ 350 automatic baud rate calculation............................. 348 auto-wake-up bit (wue) during normal operation.......................................................... 355 auto-wake-up bit (wue) during sleep.................... 355 baud rate generator with clock arbitration............. 325 brg overflow sequence ......................................... 348 brg reset due to sda arbitration during start condition.................................................. 334 brown-out reset (bor)............................................ 574 bus collision during a repeated start condition (case 1)............................................ 335 bus collision during a repeated start condition (case 2)............................................ 335 bus collision during a start condition (scl = 0) .......................................................... 334 bus collision during a stop condition (case 1)....... 336 bus collision during a stop condition (case 2)....... 336 bus collision during start condition (sda only) ....................................................... 333 bus collision for transmit and acknowledge ........... 332 capture/compare/pwm (eccp1, eccp2).............. 577 clko and i/o ........................................................... 572 clock/instruction cycle ............................................. 110 dsm carrier high synchronization (mdchsync = 1, mdclsync = 0) .............................................. 204 dsm carrier low synchronization (mdchsync = 0, mdclsync = 1) ................ 205 dsm full synchronization (mdchsync = 1, mdclsync = 1) ................ 205 dsm no synchronization (mdchsync = 0, mdclsync = 0) ................ 204 dsm on-off keying (ook) synchronization............ 204 enhanced pwm output (active-high) ...................... 278 enhanced pwm output (active-low) ....................... 279 eusart synchronous transmission (master/slave) .................................................. 586 eusart/ausart synchronous receive (master/ slave) ............................................................... 586 example spi master mode (cke = 0) ...................... 578 example spi master mode (cke = 1) ...................... 579 example spi slave mode (cke = 0) ........................ 580 example spi slave mode (cke = 1) ........................ 581 external clock .......................................................... 570 fail-safe clock monitor (fscm)............................... 482 first start bit timing ................................................. 326 full-bridge pwm output........................................... 282
pic18f66k80 family ds39977d-page 620 ? 2011 microchip technology inc. half-bridge pwm output .................................. 280, 287 high-voltage detect operation (vdirmag = 1)................................................. 393 hlvd characteristics................................................ 575 i 2 c acknowledge sequence ..................................... 331 i 2 c bus data ............................................................. 583 i 2 c bus start/stop bits.............................................. 582 i 2 c master mode (7 or 10-bit transmission) ............ 329 i 2 c master mode (7-bit reception) ........................... 330 i 2 c slave mode (10-bit reception, sen = 0, admsk = 01001) .............................................. 314 i 2 c slave mode (10-bit reception, sen = 0) ........... 315 i 2 c slave mode (10-bit reception, sen = 1) ........... 320 i 2 c slave mode (10-bit transmission)...................... 316 i 2 c slave mode (7-bit reception, sen = 0, admsk = 01011) .............................................. 312 i 2 c slave mode (7-bit reception, sen = 0) ............. 311 i 2 c slave mode (7-bit reception, sen = 1) ............. 319 i 2 c slave mode (7-bit transmission)........................ 313 i 2 c slave mode general call address sequence (7 or 10-bit addressing mode)......... 321 i 2 c stop condition receive or transmit mode ......... 331 low-voltage detect operation (vdirmag = 0)........ 392 mssp clock synchronization ................................... 318 mssp i 2 c bus data.................................................. 584 mssp i 2 c bus start/stop bits .................................. 584 parallel slave port (psp) read ................................ 200 parallel slave port (psp) write ................................ 199 pwm auto-shutdown with auto-restart enabled............................................................. 286 pwm auto-shutdown with firmware restart............ 286 pwm direction change ............................................ 283 pwm direction change at near 100% duty cycle......................................................... 284 pwm output ............................................................. 268 repeated start condition.......................................... 327 reset, watchdog timer (wdt), oscillator start-up timer (ost) and power-up timer (pwrt) ...... 573 send break character sequence ............................. 356 slave synchronization .............................................. 299 slow rise time (mclr tied to v dd , v dd rise > t pwrt )..................................................... 87 spi mode (master mode) .......................................... 298 spi mode (slave mode, cke = 0) ............................ 300 spi mode (slave mode, cke = 1) ............................ 300 steering event at beginning of instruction (strsync = 1) ................................................ 290 steering event at end of instruction (strsync = 0) ................................................ 290 synchronous reception (master mode, sren) ....... 359 synchronous transmission....................................... 357 synchronous transmission (through txen) ........... 358 time-out sequence on por w/ pll enabled (mclr tied to v dd ).............................. 88 time-out sequence on power-up (mclr not tied to v dd ), case 1........................ 87 time-out sequence on power-up (mclr not tied to v dd ), case 2........................ 87 time-out sequence on power-up (mclr tied to v dd , v dd rise t pwrt ) ............... 86 timer0 and timer1 external clock ........................... 576 timer1 gate count enable mode ............................. 223 timer1 gate single pulse mode............................... 225 timer1 gate single pulse/toggle combined mode ............................................... 226 timer1 gate toggle mode........................................ 224 timer3 gate count enable mode ............................. 234 timer3 gate single pulse mode............................... 236 timer3 gate single pulse/toggle combined mode ............................................... 237 timer3 gate toggle mode........................................ 235 transition for entry to idle mode................................. 73 transition for entry to sec_run mode ..................... 69 transition for entry to sleep mode ............................. 72 transition for two-speed start-up (intosc to hspll) ......................................... 480 transition for wake from idle to run mode ................ 73 transition for wake from sleep (hspll) ................... 72 transition from rc_run mode to pri_run mode.................................................. 71 transition from sec_run mode to pri_run mode (hspll) ................................... 69 transition to rc_run mode ...................................... 71 timing diagrams and specifications capture/compare/pwm requirements .................... 577 clko and i/o requirements............................ 572, 573 eusart/ausart synchronous receive requirements ................................................... 586 eusart/ausart synchronous transmission requirements ................................................... 586 example spi mode requirements (master mode, cke = 0)................................... 578 example spi mode requirements (master mode, cke = 1)................................... 579 example spi mode requirements (slave mode, cke = 0)..................................... 580 example spi slave mode requirements (cke = 1).......................................................... 581 external clock requirements ................................... 570 hlvd characteristics ............................................... 575 i 2 c bus data requirements (slave mode) ............... 583 i 2 c bus start/stop bits requirements (slave mode) .................................................... 582 internal rc accuracy (intosc)............................... 571 mssp i 2 c bus data requirements .......................... 585 mssp i 2 c bus start/stop bits requirements........... 584 pll clock ................................................................. 571 reset, watchdog timer, oscillator start-up timer, power-up timer and brown-out reset requirements......................................... 574 timer0 and timer1 external clock requirements ................................................... 576 top-of-stack access......................................................... 107 tstfsz ............................................................................ 527 two-speed start-up.................................................. 461, 480 ieso (config1h, internal/external oscillator switchover bit...... ................ ......... .... 464 two-word instructions example cases......................................................... 111 txstax register brgh bit .................................................................. 343
? 2011 microchip technology inc. ds39977d-page 621 pic18f66k80 family u ultra low-power mode regulators enable mode..................................................... 478 operation in sleep ............................................ 479 ultra low-power wake-up exit delay.................................................................... 80 overview ..................................................................... 79 v voltage reference specifications ..................................... 567 w watchdog timer (wdt)............................................ 461, 476 associated registers................................................ 477 control register........................................................ 477 during oscillator failure ........................................... 481 programming considerations ................................... 476 wcol ....................................................... 326, 327, 328, 331 wcol status flag.................................... 326, 327, 328, 331 www address ................................................................. 623 www, on-line support ..................................................... 11 x xorlw ............................................................................ 527 xorwf ............................................................................ 528
pic18f66k80 family ds39977d-page 622 ? 2011 microchip technology inc. notes:
? 2011 microchip technology inc. ds39977d-page 623 pic18f66k80 family the microchip web site microchip provides online support via our www site at www.microchip.com . this web site is used as a means to make files and information easily available to customers. accessible by using your favorite internet browser, the web site contains the following information: ? product support ? data sheets and errata, application notes and sample programs, design resources, user?s guides and hardware support documents, latest software releases and archived software ? general technical support ? frequently asked questions (faq), technical support requests, online discussion groups, microchip consultant program member listing ? business of microchip ? product selector and ordering guides, latest microchip press releases, listing of seminars and events, listings of microchip sales offices, distributors and factory representatives customer change notification service microchip?s customer notification service helps keep customers current on microchip products. subscribers will receive e-mail notification whenever there are changes, updates, revisions or errata related to a specified product family or development tool of interest. to register, access the microchip web site at www.microchip.com . under ?support?, click on ?customer change notification? and follow the registration instructions. customer support users of microchip products can receive assistance through several channels: ? distributor or representative ? local sales office ? field application engineer (fae) ? technical support ? development systems information line customers should contact their distributor, representative or field application engineer (fae) for support. local sales offices are also available to help customers. a listing of sales offices and locations is included in the back of this document. technical support is available through the web site at: http://support.microchip.com
pic18f66k80 family ds39977d-page 624 ? 2011 microchip technology inc. reader response it is our intention to provide you with the best documentation possible to ensure successful use of your microchip product. if you wish to provide your comments on organization, clarity, subject matter, and ways in which our documentation can better serve you, please fax your comments to the technical publications manager at (480) 792-4150. please list the following information, and use this outline to provide us with your comments about this document. to: technical publications manager re: reader response total pages sent ________ from: name company address city / state / zip / country telephone: (_______) _________ - _________ application (optional): would you like a reply? y n device: literature number: questions: fax: (______) _________ - _________ ds39977d pic18f66k80 family 1. what are the best features of this document? 2. how does this document meet your hardware and software development needs? 3. do you find the organization of this document easy to follow? if not, why? 4. what additions to the document do you think would enhance the structure and subject? 5. what deletions from the document could be made without affecting the overall usefulness? 6. is there any incorrect or misleading information (what and where)? 7. how would you improve this document?
? 2011 microchip technology inc. ds39977d-page 625 pic18f66k80 family product identification system to order or obtain information, such as pricing or delivery, refer to the factory or the listed sales office . part no. x /xx xxx pattern package temperature range device device (1,2) pic18f25k80, pic18f26k80, pic18f45k80, pic18f46k80, pic18f65k80, pic18f66k80 v dd range 1.8v to 5v pic18lf25k80, pic18lf26k80, pic18lf45k80, pic18lf46k80, pic18f65k80, pic18f66k80 v dd range 1.8v to 3.6v temperature range i = -40 ? c to +85 ? c (industrial) e= -40 ? c to +125 ? c (extended) package pdip = plastic dual in-line qfn = plastic quad flat, no lead package soic = plastic small outline spdip = skinny plastic dual in-line ssop = plastic shrink small outline tqfp = plastic thin quad flatpack pattern a) qtp, sqtp, code or special requirements (blank otherwise) examples: a) pic18f66k80-i/mr 301 = industrial temp., qfn package, extended v dd limits, qtp pattern #301. b) pic18f66k80-i/pt = industrial temp., tqfp package, extended v dd limits. note 1: f = standard voltage range lf = wide voltage range 2: t = in tape and reel, tqfp packages only.
ds39977d-page 626 ? 2011 microchip technology inc. americas corporate office 2355 west chandler blvd. chandler, az 85224-6199 tel: 480-792-7200 fax: 480-792-7277 technical support: http://support.microchip.com web address: www.microchip.com atlanta duluth, ga tel: 678-957-9614 fax: 678-957-1455 boston westborough, ma tel: 774-760-0087 fax: 774-760-0088 chicago itasca, il tel: 630-285-0071 fax: 630-285-0075 cleveland independence, oh tel: 216-447-0464 fax: 216-447-0643 dallas addison, tx tel: 972-818-7423 fax: 972-818-2924 detroit farmington hills, mi tel: 248-538-2250 fax: 248-538-2260 kokomo kokomo, in tel: 765-864-8360 fax: 765-864-8387 los angeles mission viejo, ca tel: 949-462-9523 fax: 949-462-9608 santa clara santa clara, ca tel: 408-961-6444 fax: 408-961-6445 toronto mississauga, ontario, canada tel: 905-673-0699 fax: 905-673-6509 asia/pacific asia pacific office suites 3707-14, 37th floor tower 6, the gateway harbour city, kowloon hong kong tel: 852-2401-1200 fax: 852-2401-3431 australia - sydney tel: 61-2-9868-6733 fax: 61-2-9868-6755 china - beijing tel: 86-10-8528-2100 fax: 86-10-8528-2104 china - chengdu tel: 86-28-8665-5511 fax: 86-28-8665-7889 china - chongqing tel: 86-23-8980-9588 fax: 86-23-8980-9500 china - hong kong sar tel: 852-2401-1200 fax: 852-2401-3431 china - nanjing tel: 86-25-8473-2460 fax: 86-25-8473-2470 china - qingdao tel: 86-532-8502-7355 fax: 86-532-8502-7205 china - shanghai tel: 86-21-5407-5533 fax: 86-21-5407-5066 china - shenyang tel: 86-24-2334-2829 fax: 86-24-2334-2393 china - shenzhen tel: 86-755-8203-2660 fax: 86-755-8203-1760 china - wuhan tel: 86-27-5980-5300 fax: 86-27-5980-5118 china - xian tel: 86-29-8833-7252 fax: 86-29-8833-7256 china - xiamen tel: 86-592-2388138 fax: 86-592-2388130 china - zhuhai tel: 86-756-3210040 fax: 86-756-3210049 asia/pacific india - bangalore tel: 91-80-3090-4444 fax: 91-80-3090-4123 india - new delhi tel: 91-11-4160-8631 fax: 91-11-4160-8632 india - pune tel: 91-20-2566-1512 fax: 91-20-2566-1513 japan - yokohama tel: 81-45-471- 6166 fax: 81-45-471-6122 korea - daegu tel: 82-53-744-4301 fax: 82-53-744-4302 korea - seoul tel: 82-2-554-7200 fax: 82-2-558-5932 or 82-2-558-5934 malaysia - kuala lumpur tel: 60-3-6201-9857 fax: 60-3-6201-9859 malaysia - penang tel: 60-4-227-8870 fax: 60-4-227-4068 philippines - manila tel: 63-2-634-9065 fax: 63-2-634-9069 singapore tel: 65-6334-8870 fax: 65-6334-8850 taiwan - hsin chu tel: 886-3-6578-300 fax: 886-3-6578-370 taiwan - kaohsiung tel: 886-7-213-7830 fax: 886-7-330-9305 taiwan - taipei tel: 886-2-2500-6610 fax: 886-2-2508-0102 thailand - bangkok tel: 66-2-694-1351 fax: 66-2-694-1350 europe austria - wels tel: 43-7242-2244-39 fax: 43-7242-2244-393 denmark - copenhagen tel: 45-4450-2828 fax: 45-4485-2829 france - paris tel: 33-1-69-53-63-20 fax: 33-1-69-30-90-79 germany - munich tel: 49-89-627-144-0 fax: 49-89-627-144-44 italy - milan tel: 39-0331-742611 fax: 39-0331-466781 netherlands - drunen tel: 31-416-690399 fax: 31-416-690340 spain - madrid tel: 34-91-708-08-90 fax: 34-91-708-08-91 uk - wokingham tel: 44-118-921-5869 fax: 44-118-921-5820 worldwide sales and service 08/04/10
m ? 2010 microchip technology inc. advanced information ds00000a-page 1 1.0 device overview ............................................................................................................. ........................................................... 13 2.0 guidelines for getting started with pic18fxxkxx microcontrollers ............................................................ ............................. 47 3.0 oscillator configurations ..................................... .............................................................. ......................................................... 53 4.0 power-managed modes ......................................................................................................... .................................................... 67 5.0 reset ....................................................................................................................... ................................................................... 81 6.0 memory organization ......................................................................................................... ...................................................... 105 7.0 flash program memory........................................................................................................ .................................................... 133 8.0 data eeprom memory .......................................................................................................... ................................................. 143 9.0 8 x 8 hardware multiplier................................................................................................... ....................................................... 149 10.0 interrupts ................................................................................................................. ................................................................. 151 11.0 i/o ports .................................................................................................................. ................................................................. 175 12.0 data signal modulator...................................................................................................... ........................................................ 199 13.0 timer0 module .............................................................................................................. ........................................................... 209 14.0 timer1 module .............................................................................................................. ........................................................... 213 15.0 timer2 module .............................................................................................................. ........................................................... 225 16.0 timer3 module .............................................................................................................. ........................................................... 227 17.0 timer4 modules............................................................................................................. ........................................................... 237 18.0 charge time measurement unit (ctmu) ........................................................................................ ........................................ 239 19.0 capture/compare/pwm (ccp) modules .......................................................................................... ....................................... 257 20.0 enhanced capture/compare/pwm (eccp) module................................................................................. ............................... 269 21.0 master synchronous serial port (mssp) module ............................................................................... ..................................... 291 22.0 enhanced universal synchronous asynchronous receiver transmitter (eusart) .................................................. ............. 337 23.0 12-bit analog-to-digital converter (a/d) module ............................................................................ ......................................... 361 24.0 comparator module.......................................................................................................... ........................................................ 375 25.0 comparator voltage reference module........................................................................................ ........................................... 383 26.0 high/low-voltage detect (hlvd)............................................................................................. ................................................ 387 27.0 ecan module................................................................................................................ ........................................................... 393 28.0 special features of the cpu................................................................................................ .................................................... 459 29.0 instruction set summary .................................................................................................... ...................................................... 485 30.0 development support........................................................................................................ ....................................................... 535 31.0 electrical characteristics ................................................................................................. ......................................................... 539 32.0 packaging information...................................................................................................... ........................................................ 587 appendix a: revision history................................................................................................... .......................................................... 607 appendix b: migration to pic18f66k80 family.................................................................................... ............................................. 607 index .......................................................................................................................... ....................................................................... 609 the microchip web site......................................................................................................... ............................................................ 623 customer change notification service ........................................................................................... ................................................... 623 customer support............................................................................................................... ............................................................... 623 reader response ................................................................................................................ .............................................................. 624 product identification system .................................................................................................. .......................................................... 625


▲Up To Search▲   

 
Price & Availability of PIC18F25K80ESOIC

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X